4 ms·
> In a barrier signaling and waiting is a single atomic operation. Each thread (of a group of N) reaching a barrier will wait until all N threads have reached a
by dataflow 6y ago
> In a barrier signaling and waiting is a single atomic operation. Each thread (of a group of N) reaching a barrier will wait until all N threads have reached an waited (and implicitly signaled) it.
Yeah that's exactly what std::latch::arrive_and_wait does.
I don't think atomicity is a thing here though... arrive_and_wait() is just count_down() followed by wait().
> A countdown latch is an event that will release one (or more) waiter only after has been signaled N times. Signaling and waiting threads are not necessarily the same and often are distinct sets.
C# still calls this a Barrier, except that it requires one of the waiters to be a participant (see AddParticipant() and SignalAndWait()): https://docs.microsoft.com/en-us/dotnet/api/system.threading.barrier?view=net-5.0 https://docs.microsoft.com/en-us/dotnet/api/system.threading...
They even allow removing participants!
This is a little bit like a mutex that has a try_lock. It's not strictly the vanilla Computer Science "mutex" with lock/unlock per se, but it's not a fundamentally different concept; it's just a handy yet pretty close generalization.
I guess if you really want to give this a new name then maybe it's not a terrible idea given it's a slight generalization of a barrier, but latch is certainly not going to be any more accurate (or less confusing) than barrier.
- gpderetta 6y agoYes, if you can't reset the latch, I don't think there is actually any race. I didn't realize that latch had an arrive and wait in fact.