Original post

Hi. I’ve been enthusiast for a few months. Lately I wanted to consolidate my knowledge of concurrency. The following excerpt is from the book “Concurrency in ” (by O’Reilly):

https://pastebin.com/L24Z8nd1

It works as it should (I suppose).
However if I add a few fmt.Println or another function – it deadlocks. :

https://pastebin.com/cAPbMgGv

The use of the “useless” function causes deadlock 1/~10k application runs. On the other hand, if I comment out the useless function and uncomment fmt.Println – deadlock occurs much more often.

Can somebody explain why is it happening?