Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-18 Thread Юрий Соколов
Between those two lines (fetching value from channel and sending it back to channel) channel is empty. This leads to two possible errors: - less dangerous is if some checks channel in non-blocking mode (ie select with default). Then it sees empty channel and thinks value is not set yet. - more dan

Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-18 Thread roger peppe
On 18 October 2017 at 06:05, Sokolov Yura wrote: > Following is a dangerous error-prone technique. If you use it in you program, > most likely you have a hidden bug, that will appear in high concurrency > situation. > > ``` > func wait(c chan T) T { > v := <-c > c <- v; >

Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-17 Thread Jesper Louis Andersen
If you have serious performance needs, then something like the "Disruptor" pattern is useful. There are ports of that from Java to Go out there, but I don't know how stable or useful they are. The Disruptor pattern is to keep a circular ring-buffer of elements. The writer and each reader keeps tra