3 ms·
I find an 'inverse semaphore' more useful: It blocks until it has been posted n times, where n is the init value. That way you can wait for n threads to finish
by pantalaimon 4y ago
I find an 'inverse semaphore' more useful: It blocks until it has been posted n times, where n is the init value.
That way you can wait for n threads to finish work.
- ComputerGuru 4y agoYeah, I’ve published the same (I called it a CountdownEvent) for rust and use it a lot: https://docs.rs/rsevents-extra/latest/rsevents_extra/struct.CountdownEvent.html https://docs.rs/rsevents-extra/latest/rsevents_extra/struct.... Blocks until n threads or n tasks have completed. Latter is useful in a threadpool context.
- greenbit 4y agoSounds a bit like the java.util.concurrent CyclicBarrier
- sk5t 4y agoThis is called a latch or countdown latch in the languages I use most often.
- manwe150 4y agoI believe posix pthreads calls that a barrier
- gpderetta 4y agoA barrier blocks all threads until they all have passed it right? The countdown latch is a bit different.