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 dangerous is that other goroutine may send other value to the same
channel at this moment. Then a) you have two different values that are
randomly sent to different waiters, b) some of waiters will block trying to
send value to already full channel (cause previous waiter has already sent
other value back to channel).

18 окт. 2017 г. 10:31 AM пользователь "roger peppe" <rogpe...@gmail.com>
написал:

On 18 October 2017 at 06:05, Sokolov Yura <funny.fal...@gmail.com> 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;
>         return v;
>     }
> ```

Assuming c has a capacity of 1, what's dangerous about the above?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to