Skip to content

Commit 13529cc

Browse files
chrisogopherbot
authored andcommitted
syscall: try non-blocking stdio on wasip1
Try to set stdio to non-blocking mode before the os package calls NewFile for each fd. NewFile queries the non-blocking flag but doesn't change it, even if the runtime supports non-blocking stdio. Since WebAssembly modules are single-threaded, blocking system calls temporarily halt execution of the module. If the runtime supports non-blocking stdio, the Go runtime is able to use the WASI net poller to poll for read/write readiness and is able to schedule goroutines while waiting. Change-Id: I1e3ce68a414e3c5960ce6a27fbfd38556e59c3dc Reviewed-on: https://go-review.googlesource.com/c/go/+/498196 Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Auto-Submit: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Achille Roussel <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Run-TryBot: Johan Brandhorst-Satzkorn <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 1dbbafc commit 13529cc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/syscall/fs_wasip1.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ import (
1111
"unsafe"
1212
)
1313

14+
func init() {
15+
// Try to set stdio to non-blocking mode before the os package
16+
// calls NewFile for each fd. NewFile queries the non-blocking flag
17+
// but doesn't change it, even if the runtime supports non-blocking
18+
// stdio. Since WebAssembly modules are single-threaded, blocking
19+
// system calls temporarily halt execution of the module. If the
20+
// runtime supports non-blocking stdio, the Go runtime is able to
21+
// use the WASI net poller to poll for read/write readiness and is
22+
// able to schedule goroutines while waiting.
23+
SetNonblock(0, true)
24+
SetNonblock(1, true)
25+
SetNonblock(2, true)
26+
}
27+
1428
type uintptr32 = uint32
1529
type size = uint32
1630
type fdflags = uint32

0 commit comments

Comments
 (0)