Created
March 7, 2020 04:25
-
-
Save eliben/d3af6eb67de19be728df4d265ec15ff5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Demonstrates async preemption in 1.14 vs. earlier versions | |
package main | |
import ( | |
"log" | |
"runtime" | |
"time" | |
) | |
func f1() { | |
var f float64 = 1.0 | |
for i := 0; i < 1000000000; i++ { | |
f = (f + float64(i)) / f | |
} | |
log.Println("f1", f) | |
} | |
func f2() { | |
for { | |
time.Sleep(100 * time.Millisecond) | |
log.Println("f2") | |
} | |
} | |
func main() { | |
log.SetFlags(log.LstdFlags | log.Lmicroseconds) | |
runtime.GOMAXPROCS(1) | |
go f2() | |
time.Sleep(300 * time.Millisecond) | |
go f1() | |
select {} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment