You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get the same behaviour with "go1.5rc1 linux/amd64" and "go1.4.2 linux/amd64".
Steps to reproduce
The following program sometimes gets stuck using a bit of CPU (around 40% consistantly):
// Undetected dead lock.
package main
import (
"fmt"
"sync"
"time"
)
type myType struct {
mu sync.Mutex
kill chan struct{}
ticker *time.Ticker
}
func New(interval time.Duration) *myType {
t := &myType{
kill: make(chan struct{}),
ticker: time.NewTicker(interval),
}
go func(m *myType) {
for {
select {
case <-m.kill:
m.ticker.Stop()
return
case <-m.ticker.C:
fmt.Printf("ticker locking\n")
m.mu.Lock()
fmt.Printf("tick\n")
m.mu.Unlock()
fmt.Printf("ticker unlocked\n")
}
}
}(t)
return t
}
func (m *myType) Close() {
fmt.Printf("closing\n")
m.mu.Lock()
m.kill <- struct{}{}
m.mu.Unlock()
fmt.Printf("closed\n")
}
func main() {
// Close acquires the lock but the ticker goroutine gets a ticker event
// and tries to acquire the lock as well: program uses 100% cpu and is stalled
// using nanoseconds to emphasize the issue
// got the issue with tickers using 100ms
m := New(time.Duration(10) * time.Nanosecond)
// sleeping for a little while helps on go1.5rc1 in reproducing the problem
time.Sleep(time.Duration(20) * time.Nanosecond)
m.Close()
}
Expected results
The ticker may or may not print "acquiring lock", "tick", "lock released" without getting stuck trying to get the lock.
I purpotedly sleep and tick for a tiny small amount of time to increase the chances of the issue occuring. In my original program, I had a ticker ticking in the range of 100ms to 300ms and had my program sometimes getting stuck for no reason.
The text was updated successfully, but these errors were encountered:
This is a bug in your program (you're Locking twice, and blocking inside one of your locked regions; make your kill channel buffered). Send SIGQUIT to your program (Control-) to see the deadlock. The deadlock detector is not guaranteed to tell you about everything. It only works for pretty simple cases.
Unlike some projects on Github, we don't use the Go issue tracker for Q&A, since we started with a mailing list. I recommend you post this to golang-nuts@ if you have further questions.
I get the same behaviour with "go1.5rc1 linux/amd64" and "go1.4.2 linux/amd64".
Steps to reproduce
The following program sometimes gets stuck using a bit of CPU (around 40% consistantly):
Expected results
The ticker may or may not print "acquiring lock", "tick", "lock released" without getting stuck trying to get the lock.
Actual results
Depending on the run, one of the following:
tick
ticker unlocked
closing
closed
closed
ticker locking
The last output hangs.
Additional information
I purpotedly sleep and tick for a tiny small amount of time to increase the chances of the issue occuring. In my original program, I had a ticker ticking in the range of 100ms to 300ms and had my program sometimes getting stuck for no reason.
The text was updated successfully, but these errors were encountered: