Understanding sync.cond in golang
Solution 1:
You will need the for loop because if the cond is signaled before the second coroutine waiting, it will deadlock at the Wait() because no one will signal after that.
Consider the following execution flow:
- Modify
sharedRsc
- c.Signal()
- wg.Wait()
- c.Wait()