mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
58f12ffd79
commit
bc31bcccd3
3 changed files with 60 additions and 20 deletions
|
|
@ -192,6 +192,27 @@ var preempt = func() int {
|
|||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue