[concurrency-interest] CyclicBarrier / Count Down Latch
David M. Lloyd
david.lloyd at redhat.com
Mon Apr 20 11:34:06 EDT 2009
On 04/20/2009 10:02 AM, javamann at cox.net wrote:
> I have an application that generates an unknown amount of threads at startup (via JMX MLet) and I was looking for a way to block all the threads at a certain point and then 'release' them to continue. I looked at the CyclicBarrier and CountDownLatch but they require you know the number of threads ahead of time. Currently I am just using a 'global' Condition for them to acquire and then Signal them all to continue. This seems like a hack and I am hoping there is a better way to accomplish this. Any Ideas?
I think a global condition is a perfectly adequate tool. Don't forget to
account for spurious wakeups and interruption though.
The only "problem" with a global condition is that all the threads will be
woken up at the same time, but that's really exactly what you're trying to
do, so it's not a problem in your case.
The only performance hazard I can think of offhand would be that every
awoken thread will immediately contend for the condition lock, so you'll
want to let it go as soon as possible. For very large thread+CPU counts
this might become an issue.
More information about the Concurrency-interest