wazero
wazero copied to clipboard
JIT: consider locking Goroutine thread until JIT exits
We could use runtime.LockOSThread()
to block Goruntime from switching the goroutine via async preemption which can happen at any point of execution.
Even though we've tested the JIT execution is stable without locking (as in jit/engine_test.go ), there might be still some condition where the JIT would fail.
This needs more through investigation on how Goroutine saves CPU registers when switches happens (at source code level), and more test cases to ensure whether or not we need thread blocking via LockOSThread
.
Be aware that parking/unparking threads under runtime.LockOSThread() seems to cause context switches https://github.com/golang/go/issues/21827
I suspect that locking will also cause context switches on any goroutine that have accumulated on the M in question since the last time it was locked, but I could be wrong about this.
@CannibalVox thanks for the info!