ConcurrentProgrammingWithGo icon indicating copy to clipboard operation
ConcurrentProgrammingWithGo copied to clipboard

Exercise 5.3 weighted semaphore Signal vs Broadcast

Open Bocmah opened this issue 1 year ago • 0 comments

Hello! Thanks for a great book, enjoying it so far.

I have a question about weighted semaphore exercise. Why do we use Signal here instead of Broadcast?

Suppose goroutine g1 is holding 2 permits. And suppose there are g2 and g3 goroutine each trying to acquire one permit.

Then suppose g1 finishes and releases 2 permits. Isn't it more beneficial (and maybe even more correct) to broadcast here, so g2 and g3 both can acquire a permit?

Maybe I'm misunderstanding something.

https://github.com/cutajarj/ConcurrentProgrammingWithGo/blob/b3d5bcf683a946ac9ef15d34a0545c2a843e0593/exercises/chapter5/exercise5.3/weightedsemaphore.go#L33

Bocmah avatar Dec 09 '24 19:12 Bocmah