mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
compiler,runtime: implement stack-based scheduler
This scheduler is intended to live along the (stackless) coroutine based scheduler which is needed for WebAssembly and unsupported platforms. The stack based scheduler is somewhat simpler in implementation as it does not require full program transform passes and supports things like function pointers and interface methods out of the box with no changes. Code size is reduced in most cases, even in the case where no scheduler scheduler is used at all. I'm not exactly sure why but these changes likely allowed some further optimizations somewhere. Even RAM is slightly reduced, perhaps some global was elminated in the process as well.
This commit is contained in:
committed by
Ron Evans
parent
61f711ef26
commit
542135c357
Vendored
+11
-9
@@ -27,9 +27,9 @@ func main() {
|
||||
|
||||
// Test multi-sender.
|
||||
ch = make(chan int)
|
||||
go fastsender(ch)
|
||||
go fastsender(ch)
|
||||
go fastsender(ch)
|
||||
go fastsender(ch, 10)
|
||||
go fastsender(ch, 23)
|
||||
go fastsender(ch, 40)
|
||||
slowreceiver(ch)
|
||||
|
||||
// Test multi-receiver.
|
||||
@@ -57,9 +57,10 @@ func main() {
|
||||
go fastreceiver(ch)
|
||||
select {
|
||||
case ch <- 5:
|
||||
println("select one sent")
|
||||
}
|
||||
close(ch)
|
||||
time.Sleep(time.Millisecond)
|
||||
println("did send one")
|
||||
|
||||
// Test select with a single recv operation (transformed into chan recv).
|
||||
select {
|
||||
@@ -124,17 +125,18 @@ func sendComplex(ch chan complex128) {
|
||||
ch <- 7 + 10.5i
|
||||
}
|
||||
|
||||
func fastsender(ch chan int) {
|
||||
ch <- 10
|
||||
ch <- 11
|
||||
func fastsender(ch chan int, n int) {
|
||||
ch <- n
|
||||
ch <- n + 1
|
||||
}
|
||||
|
||||
func slowreceiver(ch chan int) {
|
||||
sum := 0
|
||||
for i := 0; i < 6; i++ {
|
||||
n := <-ch
|
||||
println("got n:", n)
|
||||
sum += <-ch
|
||||
time.Sleep(time.Microsecond)
|
||||
}
|
||||
println("sum of n:", sum)
|
||||
}
|
||||
|
||||
func slowsender(ch chan int) {
|
||||
|
||||
Vendored
+2
-7
@@ -10,12 +10,7 @@ received num: 7
|
||||
received num: 8
|
||||
recv from closed channel: 0 false
|
||||
complex128: (+7.000000e+000+1.050000e+001i)
|
||||
got n: 10
|
||||
got n: 11
|
||||
got n: 10
|
||||
got n: 11
|
||||
got n: 10
|
||||
got n: 11
|
||||
sum of n: 149
|
||||
sum: 25
|
||||
sum: 29
|
||||
sum: 33
|
||||
@@ -23,8 +18,8 @@ sum(100): 4950
|
||||
deadlocking
|
||||
select no-op
|
||||
after no-op
|
||||
select one sent
|
||||
sum: 5
|
||||
did send one
|
||||
select one n: 0
|
||||
select n from chan: 55
|
||||
select n from closed chan: 0
|
||||
|
||||
Reference in New Issue
Block a user