Open viralmutant opened 5 years ago
The fact that two threads will see that count == n
and both will call barrier.signal()
doesn't change the functionality of the one-time barrier discussed in 3.6.x., since the code doesn't reuse this barrier - so its final state doesn't matter, since the guarantees made by the barrier are held.
It matters in 3.7.1 because if the turnstile is over-signaled then its internal counter will not be zero when we re-use the barrier and hit line 9 again, which means the barrier will be opened before all N threads reached it.
The fact that two threads will see that
count == n
and both will callbarrier.signal()
doesn't change the functionality of the one-time barrier discussed in 3.6.x., since the code doesn't reuse this barrier - so its final state doesn't matter, since the guarantees made by the barrier are held. It matters in 3.7.1 because if the turnstile is over-signaled then its internal counter will not be zero when we re-use the barrier and hit line 9 again, which means the barrier will be opened before all N threads reached it.
Yup !! Got it. Thanks
But I have 1 more doubt in 'Preloaded Turnstile' solution. Since we have signal(n)
construct, we can very well re-use a single turnstile
, right ? Instead of having turnstile
and turnstile2
?
Or is it that they are explaining how to re-use Barrier in general and what goes inside the python Barrier
class(as explained in the next section), b'coz re-usable barrier object in python is from where my confusion stemmed.
The problem described in the Section 3.7.2 for the non-solution in 3.7.1 is
Isn't this also true for the working solution described in 3.6.4 ? The text under that head says