mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
all: rewrite goroutine lowering
Before this commit, goroutine support was spread through the compiler. This commit changes this support, so that the compiler itself only generates simple intrinsics and leaves the real support to a compiler pass that runs as one of the TinyGo-specific optimization passes. The biggest change, that was done together with the rewrite, was support for goroutines in WebAssembly for JavaScript. The challenge in JavaScript is that in general no blocking operations are allowed, which means that programs that call time.Sleep() but do not start goroutines also have to be scheduled by the scheduler.
This commit is contained in:
Vendored
+22
@@ -9,6 +9,18 @@ func main() {
|
||||
println("main 2")
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
println("main 3")
|
||||
|
||||
// Await a blocking call. This must create a new coroutine.
|
||||
println("wait:")
|
||||
wait()
|
||||
println("end waiting")
|
||||
|
||||
// Run a non-blocking call in a goroutine. This should be turned into a
|
||||
// regular call, so should be equivalent to calling nowait() without 'go'
|
||||
// prefix.
|
||||
go nowait()
|
||||
time.Sleep(time.Millisecond)
|
||||
println("done with non-blocking goroutine")
|
||||
}
|
||||
|
||||
func sub() {
|
||||
@@ -16,3 +28,13 @@ func sub() {
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
println("sub 2")
|
||||
}
|
||||
|
||||
func wait() {
|
||||
println(" wait start")
|
||||
time.Sleep(time.Millisecond)
|
||||
println(" wait end")
|
||||
}
|
||||
|
||||
func nowait() {
|
||||
println("non-blocking goroutine")
|
||||
}
|
||||
|
||||
Vendored
+6
@@ -3,3 +3,9 @@ sub 1
|
||||
main 2
|
||||
sub 2
|
||||
main 3
|
||||
wait:
|
||||
wait start
|
||||
wait end
|
||||
end waiting
|
||||
non-blocking goroutine
|
||||
done with non-blocking goroutine
|
||||
|
||||
Reference in New Issue
Block a user