AllenDowney / LittleBookOfSemaphores

LaTeX source and supporting code for The Little Book of Semaphores, by Allen Downey.
273 stars 77 forks source link

Reading count value outside of mutex in Barrier solution #35

Open viralmutant opened 1 year ago

viralmutant commented 1 year ago

The Barrier solution in 3.6.4 has a note towards the end:

It might seem dangerous to read the value of count outside the mutex. In this case it is not a problem, but in general it is probably not a good idea.

I did not understand why it is not a problem in this case. If all the threads signal() the barrier, then none of them will wait(), right ?