~eliasnaur/gio

3 3

"Graphics" dedicated thread

Details
Message ID
<i97VxsYP1ynbeLnci1FmTRs9UuhM5ZbgOo4VWlgs1I@cp4-web-030.plabs.ch>
DKIM signature
missing
Download raw message
hi,

(apologies for the barrage of emails)

IIUC, we currently need to run the "graphics" event loop on the main
OS-thread because that's what the underlying C-libraries and/or the
drivers they talk to are using as a programming model.

so we have this whole runtime.LockOSThread + goroutines-serving
callbacks scaffolding.
(the same is done, if I am not mistaken, for, e.g., debugging and ptrace)

from a developer point of view, it's fine, I guess, and once you
understand the underlying constraints, that makes sense.
but from a user point of view, or a consumer of such a package, it's a
bit of a pain: the user's main need to be modified and parts of its
logical flow as well.

so, here is my question after this rather lengthy introduction:
did somebody ever floated the idea of having yet another "//go:xyz"
magical comment decoration be understood by the Go toolchain to be able
to not bleed too much implementation details?

ideally, we could have something like:

package app

//go:lock-main-thread
func Main() { ... }


and have user code do just:

package main

import "gioui.org/app"

func init() {
    go app.Main()
}

and be done with it.
this would dramatically simplify user code.
(this would of course be done at the price of complicating a bit more
Go's runtime, or at least Go idioms)

what do you think? was this already proposed to Go core?

-s
Alessandro Arzilli
Details
Message ID
<20201210202219.hiti4blrsjmyijge@kra>
In-Reply-To
<i97VxsYP1ynbeLnci1FmTRs9UuhM5ZbgOo4VWlgs1I@cp4-web-030.plabs.ch> (view parent)
DKIM signature
pass
Download raw message
On Thu, Dec 10, 2020 at 08:04:14PM +0000, Sebastien Binet wrote:
> hi,
> 
> (apologies for the barrage of emails)
> 
> IIUC, we currently need to run the "graphics" event loop on the main
> OS-thread because that's what the underlying C-libraries and/or the
> drivers they talk to are using as a programming model.
> 
> so we have this whole runtime.LockOSThread + goroutines-serving
> callbacks scaffolding.
> (the same is done, if I am not mistaken, for, e.g., debugging and ptrace)
> 
> from a developer point of view, it's fine, I guess, and once you
> understand the underlying constraints, that makes sense.
> but from a user point of view, or a consumer of such a package, it's a
> bit of a pain: the user's main need to be modified and parts of its
> logical flow as well.
> 
> so, here is my question after this rather lengthy introduction:
> did somebody ever floated the idea of having yet another "//go:xyz"
> magical comment decoration be understood by the Go toolchain to be able
> to not bleed too much implementation details?
> 
> ideally, we could have something like:
> 
> package app
> 
> //go:lock-main-thread
> func Main() { ... }
> 
> 
> and have user code do just:
> 
> package main
> 
> import "gioui.org/app"
> 
> func init() {
>     go app.Main()
> }
> 
> and be done with it.
> this would dramatically simplify user code.
> (this would of course be done at the price of complicating a bit more
> Go's runtime, or at least Go idioms)
> 
> what do you think? was this already proposed to Go core?
> 
> -s
> 
> 

What happens if Main gets called and there already is a goroutine locked to
the main thread?
Details
Message ID
<CANtNKfqmPB0YqnMaheMMV9rW-QK4exwd37GRtZbyVeyt7tkSXw@mail.gmail.com>
In-Reply-To
<i97VxsYP1ynbeLnci1FmTRs9UuhM5ZbgOo4VWlgs1I@cp4-web-030.plabs.ch> (view parent)
DKIM signature
pass
Download raw message
Doesn't locking os thread in init serve the same purpose?

    func init() { runtime.LockOSThread() }

On Thu, Dec 10, 2020 at 10:04 PM Sebastien Binet <s@sbinet.org> wrote:
>
> hi,
>
> (apologies for the barrage of emails)
>
> IIUC, we currently need to run the "graphics" event loop on the main
> OS-thread because that's what the underlying C-libraries and/or the
> drivers they talk to are using as a programming model.
>
> so we have this whole runtime.LockOSThread + goroutines-serving
> callbacks scaffolding.
> (the same is done, if I am not mistaken, for, e.g., debugging and ptrace)
>
> from a developer point of view, it's fine, I guess, and once you
> understand the underlying constraints, that makes sense.
> but from a user point of view, or a consumer of such a package, it's a
> bit of a pain: the user's main need to be modified and parts of its
> logical flow as well.
>
> so, here is my question after this rather lengthy introduction:
> did somebody ever floated the idea of having yet another "//go:xyz"
> magical comment decoration be understood by the Go toolchain to be able
> to not bleed too much implementation details?
>
> ideally, we could have something like:
>
> package app
>
> //go:lock-main-thread
> func Main() { ... }
>
>
> and have user code do just:
>
> package main
>
> import "gioui.org/app"
>
> func init() {
>     go app.Main()
> }
>
> and be done with it.
> this would dramatically simplify user code.
> (this would of course be done at the price of complicating a bit more
> Go's runtime, or at least Go idioms)
>
> what do you think? was this already proposed to Go core?
>
> -s
>
>
Details
Message ID
<C7Q32FTBOBZ9.F7FFBGL3LUKU@themachine>
In-Reply-To
<CANtNKfqmPB0YqnMaheMMV9rW-QK4exwd37GRtZbyVeyt7tkSXw@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Thu Dec 10, 2020 at 22:24, Egon Elbre wrote:
> Doesn't locking os thread in init serve the same purpose?
>
>     func init() { runtime.LockOSThread() }
>

Yes, and that's what Gio does on the platforms that need it:

https://git.sr.ht/~eliasnaur/gio/tree/main/internal/rendertest/util_test.go#L190

FWIW, I don't think Go should make special provisions for what I
consider a broken threading model. Linux has never had that "main
thread" requirement, and Windows only binds a window to the current
thread, not some global main thread.

Elias
Reply to thread Export thread (mbox)