1
0
mirror of https://github.com/golang/go synced 2024-11-13 19:10:22 -07:00

runtime: add more tests for LockOSThread()

Just test some additional paths through the scheduler.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7331044
This commit is contained in:
Dmitriy Vyukov 2013-02-15 00:02:12 +04:00
parent 11884db3d7
commit 6a828482fa

View File

@ -8,6 +8,7 @@ import (
"runtime"
"sync/atomic"
"testing"
"time"
)
var stop = make(chan bool, 1)
@ -45,6 +46,36 @@ func TestStopTheWorldDeadlock(t *testing.T) {
runtime.GOMAXPROCS(maxprocs)
}
func TestYieldLocked(t *testing.T) {
const N = 10
c := make(chan bool)
go func() {
runtime.LockOSThread()
for i := 0; i < N; i++ {
runtime.Gosched()
time.Sleep(time.Millisecond)
}
c <- true
// runtime.UnlockOSThread() is deliberately omitted
}()
<-c
}
func TestBlockLocked(t *testing.T) {
const N = 10
c := make(chan bool)
go func() {
runtime.LockOSThread()
for i := 0; i < N; i++ {
c <- true
}
runtime.UnlockOSThread()
}()
for i := 0; i < N; i++ {
<-c
}
}
func stackGrowthRecursive(i int) {
var pad [128]uint64
if i != 0 && pad[0] == 0 {