-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Description
by VisualFC:
The time.Sleep goroutines locked What steps will reproduce the problem? {{{ package main import ( "fmt" "time" "sync" ) var newTimerMutex sync.Mutex func MutexSleep(ns int64) { newTimerMutex.Lock() t := time.NewTimer(ns) newTimerMutex.Unlock() <-t.C } func main() { ch := make(chan int) exit := make(chan bool) go func() { index := 0 for { i := <-ch fmt.Printf("%d.", i) index++ if index >= 100000 { break } } exit <- true }() for i := 0; i < 100000; i++ { go func(i int, ch chan int) { time.Sleep(1e9) //MutexSleep(1e9) ch <- i }(i, ch) } <-exit } }}} What is the expected output? runtime: failed to create new OS thread (have 941 already; errno=11) throw: runtime.newosproc goroutine 942 [syscall]: syscall.Syscall6() /home/win32/go/src/pkg/syscall/asm_linux_amd64.s:40 +0x5 syscall.Select(0x0, 0x0, 0x0, 0x0, 0xf84281c330, ...) /home/win32/go/src/pkg/syscall/zsyscall_linux_amd64.go:1008 +0x63 syscall.Sleep(0x3b9aca00, 0x0, 0xf84281c340, 0x41f77d) /home/win32/go/src/pkg/syscall/syscall_linux.go:189 +0x7a time.sysSleep(0x3b9aca00, 0x0, 0x4e571ee8, 0x123d725925d91b70) /home/win32/go/src/pkg/time/sys_posix.go:13 +0x25 time.sleep(0x123d7258ea3e5170, 0x3b9aca00, 0x0, 0x0, 0x0, ...) /home/win32/go/src/pkg/time/sys.go:44 +0x40 time.Sleep(0x3b9aca00, 0x0, 0x0, 0x40c9f1) /home/win32/go/src/pkg/time/sys.go:33 +0x33 main._func_002(0xf8000003ab, 0xf8400019b0, 0x0, 0x0) /home/win32/dev/test.go:35 +0x24 created by main.main /home/win32/dev/test.go:38 +0xd5 What do you see instead? application exceptsion Which compiler are you using (5g, 6g, 8g, gccgo)? 6g,8g Which operating system are you using? CentOS6.0 WINDOWS7 Which revision are you using? (hg identify) weekly.2011-08-17 and 88744261dd47 tip Please provide any additional information below. use MutexSleep(1e9) the application normal