mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
wasm: don't block //go:wasmexport because of running goroutines
This fixes bug https://github.com/tinygo-org/tinygo/issues/4874.
This commit is contained in:
committed by
Ron Evans
parent
0c2ab895b7
commit
612a38e363
@@ -92,6 +92,10 @@ func wasmExportRun(done *bool) {
|
||||
//
|
||||
// This function is not called when the scheduler is disabled.
|
||||
func wasmExportExit() {
|
||||
// Signal to the scheduler that it should return, since this call to a
|
||||
// //go:wasmexport function has exited.
|
||||
schedulerExit = true
|
||||
|
||||
task.Pause()
|
||||
|
||||
// TODO: we could cache the allocated stack so we don't have to keep
|
||||
|
||||
@@ -30,6 +30,10 @@ const hasParallelism = false
|
||||
// Set to true after main.main returns.
|
||||
var mainExited bool
|
||||
|
||||
// Set to true when the scheduler should exit after the next switch to the
|
||||
// scheduler. This is a special case for //go:wasmexport.
|
||||
var schedulerExit bool
|
||||
|
||||
// Queues used by the scheduler.
|
||||
var (
|
||||
runqueue task.Queue
|
||||
@@ -214,6 +218,13 @@ func scheduler(returnAtDeadlock bool) {
|
||||
// Run the given task.
|
||||
scheduleLogTask(" run:", t)
|
||||
t.Resume()
|
||||
|
||||
// The last call to Resume() was a signal to stop the scheduler since a
|
||||
// //go:wasmexport function returned.
|
||||
if GOARCH == "wasm" && schedulerExit {
|
||||
schedulerExit = false // reset the signal
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ const hasParallelism = false
|
||||
// Set to true after main.main returns.
|
||||
var mainExited bool
|
||||
|
||||
// dummy flag, not used without scheduler
|
||||
var schedulerExit bool
|
||||
|
||||
// run is called by the program entry point to execute the go program.
|
||||
// With the "none" scheduler, init and the main function are invoked directly.
|
||||
func run() {
|
||||
|
||||
Reference in New Issue
Block a user