Even if you could I don’t think you would want to do it this way. Have a go routine sleep on a channel. Post to the channel from the native code.
Let your command loop run on any thread and synchronize via a channel the calls to/from native. The os event loop doesn’t need to run on main - it just needs to be locked to a thread - use a native thread - and post the os events to a channel. Probably easiest to export a simple Go postToEventChannel() and have the native use this. > On Jan 3, 2020, at 2:18 PM, bucha...@gmail.com wrote: > > > I've been getting by with a version of this that sends commands (closures) to > a loop on the main thread: > https://github.com/buchanae/ink/blob/2af8781a960a0351b6b6b7ca23d81ae5c43535ec/win/window.go#L55 > > And here is where it pops those commands, and also integrates with the OS > event loop: > https://github.com/buchanae/ink/blob/2af8781a960a0351b6b6b7ca23d81ae5c43535ec/win/window.go#L163 > > But, I'm still not satisfied. The solution ties together the scheduling (and > code) of two separate event loops. In particular, I've found that my commands > are delayed ~10ms – I think sdl.WaitEvent might be rate limited. > > What I really want is for the two event loops (OS event loop vs app command > loop) to be in two separate goroutines, both running on the main thread. That > way, the OS event loop can react to infrequent window events (mouse clicks, > etc) without burning lots of CPU, while my app command loop can react to > commands instantly. > > Does that make sense? Is this possible to implement without requiring a > change to the Go runtime? Is it possible to change the Go runtime to allow > multiple goroutines to be scheduled only to the main thread? > > Thanks. > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/e4e3a04d-0f76-4baf-9760-9992ef38d51f%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/FFE5D51B-757C-4045-8C70-A764D32E9CEA%40ix.netcom.com.