Re: [go-nuts] Deadlocking on channels

2017-01-21 Thread Alex Bucataru
s://play.golang.org/p/fqPXXpNufO >> >> It ran for much longer before locking on the same line! Trouble is, now >> I can't actually see the lock whereas I could before! >> >> I'm wondering if I should keep a global channelMap and lock that with >> sync.R

Re: [go-nuts] Deadlocking on channels

2017-01-20 Thread Alex Bucataru
Actually, a buffered channel alone is not enough... A more robust solution is to move the shutdown branch in jobDispatcher into a function; then call this function in a goroutine of its own right after you create shutdown channel. That will prevent the message sending and channel closing from d

Re: [go-nuts] Deadlocking on channels

2017-01-20 Thread Alex Bucataru
Your deadlock happens because the message channel is not buffered. The jobDispatcher goroutine is blocked waiting for channel to accept msg, while the processPackets packets just sent the shutdown signal and exited (on the time.Ticker branch of the select). A buffer of any size, even 1, would a

[go-nuts] Re: syscall.Read() with timeout: syscall.Select() vs golang's select statement

2016-07-24 Thread Alex Bucataru
Hi Fabian, You could add a signal channel to tell your goroutine to exit. Editing your pseudo code: data := make(chan byte) done := make(chan struct{}) fd := some file descriptor go func() { buf = make([]byte, 1) for { n, err = syscall.Read(fd, buf) if err != nil {