forked from joejulian/gio
app: [macOS] run main.main off the main thread when Gio is embedded
When Gio is embedded (such as on Android and iOS), we pretend that the Go library is the main program by running Go main on the main thread. To avoid deadlock, `app.Main` returns immediately to relinquish control of the main thread. This behaviour is suprising (what if something else runs after `app.Main`?) and more importantly is not compatible with app global events received by the main goroutine. Something had to give, and this change starts a new goroutine for calling Go's main. Signed-off-by: inkeliz <inkeliz@inkeliz.com> Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -1318,6 +1318,7 @@ func findClass(env *C.JNIEnv, name string) C.jclass {
|
||||
}
|
||||
|
||||
func osMain() {
|
||||
select {}
|
||||
}
|
||||
|
||||
func newWindow(window *callbacks, options []Option) {
|
||||
|
||||
+4
-2
@@ -405,11 +405,12 @@ const (
|
||||
)
|
||||
|
||||
func osMain() {
|
||||
switch mainMode {
|
||||
case mainModeUndefined:
|
||||
if !isMainThread() {
|
||||
panic("app.Main must be run on the main goroutine")
|
||||
}
|
||||
switch mainMode {
|
||||
case mainModeUndefined:
|
||||
|
||||
mainMode = mainModeExe
|
||||
var argv []*C.char
|
||||
for _, arg := range os.Args {
|
||||
@@ -423,6 +424,7 @@ func osMain() {
|
||||
case mainModeLibrary:
|
||||
// Do nothing, we're embedded as a library.
|
||||
}
|
||||
select {}
|
||||
}
|
||||
|
||||
//export gio_runMain
|
||||
|
||||
+1
-1
@@ -25,6 +25,6 @@ func runMain() {
|
||||
// Indirect call, since the linker does not know the address of main when
|
||||
// laying down this package.
|
||||
fn := mainMain
|
||||
fn()
|
||||
go fn()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user