Skip to content

Instantly share code, notes, and snippets.

@akimasa
Created April 30, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimasa/fc3114b223cc043d78d8274eca2b3ba6 to your computer and use it in GitHub Desktop.
Save akimasa/fc3114b223cc043d78d8274eca2b3ba6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"runtime"
"sync"
)
var mutex *sync.Mutex
func main() {
mutex := new(sync.Mutex)
ch := make(chan bool)
go func() {
for i := 0; i < 10; i++ {
<-ch
}
}() //何らかの原因ですぐ止まる
go func() {
for n := 0; n < 100; n++ {
mutex.Lock()
ch <- true
mutex.Unlock()
}
}() //しかし送り続けている
for i := 0; i < 1000; i++ {
go func() {
mutex.Lock()
// 色々処理...
mutex.Unlock()
}() //こいつがリークする。
}
fmt.Println(runtime.NumGoroutine()) //1000以上になっている
mutex.Lock()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment