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:
Ayke van Laethem
2019-08-13 12:35:46 +02:00
committed by Ron Evans
parent 61f711ef26
commit 542135c357
17 changed files with 702 additions and 224 deletions
+11 -9
View File
@@ -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) {
+2 -7
View File
@@ -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