3 ms·
Had a mentor who said one of the biggest problems in computer science is that all the good metaphors are already taken.
by pfarrell 6y ago
Had a mentor who said one of the biggest problems in computer science is that all the good metaphors are already taken.
- dataflow 6y agoBut in this case the concept already had a name in CS and it was called a barrier (which is a pretty apt name too). For some rename they called it a latch and then they called a cyclic barrier a barrier...
- gpderetta 6y agoAs far as I can tell, a (countdown) latch is different from a barrier. 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. 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. I guess you could build a barrier from a countdown latch, but I suspect that a trivial mapping of barrier::wait to latch::signal+wait is going to racey and you need an additional sinchronization primitive. For example pthread_barrier_wait requires an additional mutex (similar to condition variables). edit: std::barrier has (optionally) separate singal+wait and uses an explicit arrival token instead of a mutex to tie the signaling with waiting. In practice a barrier and a countdown latch are used for different purposes (the former to coordinate multiple symmetric threads across phases of a distributed computation, the latter to wait for completion of N events).
- 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.
- bierjunge 6y agoI don't know who said the following, but it sums up CS pretty good: "There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."
- MaxBarraclough 6y agoIt's interesting how we've used all the various 'doing' words in English for different technical concepts, although with some overlap. Function, method, procedure, action, operation, routine, task, process.