A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. CyclicBarriers are useful in programs involving a fixed sized party of threads that must occasionally wait for each other. The barrier is called cyclic because it can be re-used after the waiting threads are released.
Questions tagged [cyclicbarrier]
70 questions
180
votes
14 answers
Java concurrency: Countdown latch vs Cyclic barrier
I was reading through the java.util.concurrent API, and found that
CountDownLatch: A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes.
CyclicBarrier: A…

daydreamer
- 87,243
- 191
- 450
- 722
22
votes
9 answers
Resettable CountdownLatch
I need something which is directly equivalent to CountDownLatch, but is resettable (remaining thread-safe!). I can't use classic synchronisation constructs as they simply don't work in this situation (complex locking issues). At the moment, I'm…

Chris Dennett
- 22,412
- 8
- 58
- 84
15
votes
6 answers
What is the fastest cyclic synchronization in Java (ExecutorService vs. CyclicBarrier vs. X)?
Which Java synchronization construct is likely to provide the best
performance for a concurrent, iterative processing scenario with a
fixed number of threads like the one outlined below? After experimenting
on my own for a while (using…
Alex Dunlop
11
votes
4 answers
Is my code thread-unsafe?
I have wrote code to understand CyclicBarrier.
My application emulates election. Each rounds selects candidate with small votes and this candidate eliminates from the race for victory.
source:
class ElectoralCommission {
public volatile boolean…

gstackoverflow
- 36,709
- 117
- 359
- 710
11
votes
1 answer
When to reset CyclicBarrier in java multithreading
I was reading CyclicBarrier in the following link
http://java-latte.blogspot.in/2013/10/cyclicbarrier-in-java-concurrency.html.
In the example 1, CyclicRaceDemo.java main method, CyclicBarrier is being reused without calling reset method.
I ran the…

Anand
- 20,708
- 48
- 131
- 198
8
votes
1 answer
What is the purpose of await() in CountDownLatch?
I have the following program, where I am using java.util.concurrent.CountDownLatch and without using await() method it's working fine.
I am new to concurrency and want to know the purpose of await(). In CyclicBarrier I can understand why await() is…

NewToJava
- 149
- 2
- 11
7
votes
3 answers
How to implement Barrier class from .NET 4 functionality in .NET 3.5
For some reasons I have to stick to .NET 3.5 and I need a functionality of Barrier class from .NET 4. I have a bunch of threads that do some work and I want them to wait for each other until all are done. When all are done I want that they do the…

Kiter
- 71
- 2
7
votes
4 answers
How do I get the java.concurrency.CyclicBarrier to work as expected
I am writing code that will spawn two thread and then wait for them to sync up using the CyclicBarrier class. Problem is that the cyclic barrier isn't working as expected and the main thread doesnt wait for the individual threads to finish. Here's…

Ritesh M Nayak
- 8,001
- 14
- 49
- 78
6
votes
1 answer
Ideas to avoid doing a trick on CyclicBarrier
I was running some tests with parallel processing and made a program that given a matrix of integers re-calcutes each position's value based on the neighbours.
I needed a copy of the matrix so the values wouldn't be overriden and used a…

dabadaba
- 9,064
- 21
- 85
- 155
4
votes
2 answers
Cyclic Barrier in java
I have a list which needs to be populated by three parties(threads,lets say).I am using cyclic barrier to achieve this functionality. Everything works fine except that I am not able to use the resulted list without inducing a forced sleep. Below is…

viks1010
- 101
- 8
4
votes
1 answer
ExecutorService with Runnable share CyclicBarrier
I have a problem in a concurrent solution in Java using n Runnable class that share a CyclicBarrier, and the Runnable are handled by a ExecutorService, this is the code:
public class Worker implements Runnable {
private CyclicBarrier…

Piero
- 9,173
- 18
- 90
- 160
3
votes
3 answers
What is C++ version of Java's cyclic barrier?
In java, multiple threads can wait all others at a certain point so that they don't start a new block of codes before all others finish first block:
CyclicBarrier barrier = new CyclicBarrier(2);
// thread…

huseyin tugrul buyukisik
- 11,469
- 4
- 45
- 97
3
votes
3 answers
Barrier break down example
I am reading the book Java Concurrency in Practice where it says,
CyclicBarrier allows a fixed number of parties to rendezvous repeatedly at a barrier point and is useful in parallel iterative algorithms that break down a problem into a fixed…

peter
- 8,333
- 17
- 71
- 94
2
votes
2 answers
Java - gracefully quit threads
I got a bunch of threads that perform calculations. They are "synchronized" using a CyclicBarrier. When any thread's run() method finishes, I want all other threads to exit as well once they call await() on the barrier the next time.
So far,…

ryyst
- 9,563
- 18
- 70
- 97
2
votes
0 answers
Control order of threads after cyclic barrier has completed its action?
Is there any way I could control the order in which threads should resume its work after cyclic barrier "Barrier Action" has been completed?
Following is an example which I tried but order of final 2 statements keep changing but I don't want that to…

Jaspreet Jolly
- 1,235
- 11
- 26