runtime: preempt long-running goroutines
If a goroutine runs for more than 10ms, preempt it.
Update #543.
R=rsc
CC=golang-dev
https://golang.org/cl/10796043
diff --git a/src/pkg/runtime/proc_test.go b/src/pkg/runtime/proc_test.go
index 29e65da..b509826 100644
--- a/src/pkg/runtime/proc_test.go
+++ b/src/pkg/runtime/proc_test.go
@@ -192,6 +192,27 @@
return sum
}
+func TestPreemption(t *testing.T) {
+ t.Skip("preemption is disabled")
+ // Test that goroutines are preempted at function calls.
+ const N = 5
+ c := make(chan bool)
+ var x uint32
+ for g := 0; g < 2; g++ {
+ go func(g int) {
+ for i := 0; i < N; i++ {
+ for atomic.LoadUint32(&x) != uint32(g) {
+ preempt()
+ }
+ atomic.StoreUint32(&x, uint32(1-g))
+ }
+ c <- true
+ }(g)
+ }
+ <-c
+ <-c
+}
+
func TestPreemptionGC(t *testing.T) {
t.Skip("preemption is disabled")
// Test that pending GC preempts running goroutines.