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
1
vote
2 answers
Why cannot `ExecutorService` consistently schedule threads?
I am attempting to reimplement my concurrent code using CyclicBarrier which is new to me. I can do without it but am time trialling it against my other solution, the problem I have is a deadlock situation with the following code:
//instance…

John
- 6,433
- 7
- 47
- 82
1
vote
5 answers
Multithreaded application increases runtime with number of threads
I am implementing a multithreaded solution of the Barnes-Hut algorithm for the N-Body problem.
Main class does the following
public void runSimulation() {
for(int i = 0; i < numWorkers; i++) {
new Thread(new Worker(i, this,…

ChristianG
- 11
- 3
1
vote
1 answer
Is it possible to allow waiting in the main thread in javascript
I am currently working with Web Workers and for some testing purposes it would be nice if it was possible to wait in the main thread until workers have finished what they're doing. So:
Main thread -> start workers
Main thread -> wait for workers to…

PNS
- 750
- 1
- 5
- 19
1
vote
3 answers
Better ways to handle exceptions related to Cyclic Barriers
I am trying to map some business case to usage of Cyclic Barriers. Let's say we have a promotional offer going on and only 3 customers can get the promotional offer. The rest will not get the offer.
To map this scenario, I have made use of Cyclic…

user3842182
- 371
- 2
- 5
- 8
1
vote
1 answer
How to make threads work in order using CountDownlatch?
I am learning how to use countdownLatch in java, and i created a simple example as shown below inthe code.
what i learnt about that mechanism is, it is just a way to force only ONE thread to wait for others till they finish their work, then that…

rmaik
- 1,076
- 3
- 15
- 48
1
vote
2 answers
Using cyclic barrier does not wait till all threads finish
Here is what I am trying to do. I have a number of threads which should all wait at a common point before they proceed, so obvious solution is to use CyclicBarrier. But I want to also compute the total time taken by the threads to execute. I defined…

akhil_mittal
- 23,309
- 7
- 96
- 95
1
vote
1 answer
CyclicBarrier on worker threads
I have a function which splits an array into smaller pieces.
Each piece is then evaluated in a separate thread.
The results are populated into a common list.
private void sortandkeep(int[] arr){
traversed.add(arr);
…

IUnknown
- 9,301
- 15
- 50
- 76
1
vote
3 answers
Java looping Threads using CyclicBarrier
I have a program with this general structure:
init
create CyclicBarrier
initialise all threads, attaching to barrier
*start all threads*
wait for join
display stats
*start all threads*
perform calculation
await barrier
My problem is I need the…

dylanslewis
- 33
- 7
1
vote
1 answer
CyclicBarrier: Of 'x' threads that cause the barrier to trip 'y' complete their execution and terminate
I have a CyclicBarrier that will trip when 'x' number of parties (threads) are waiting upon it. Among these 'x' threads 'y' have very small life spans and terminate much quickly after completing their execution successfully. Now, the barrier keeps…

user1071840
- 3,522
- 9
- 48
- 74
1
vote
1 answer
Cyclic barrier reuse?
I'm currently trying to implement an application to communicate with a machine, and it should essentially work as follows:
The program sends a message to the server (in this case, the first 255 bytes of a file).
The machine responds with a…

Jose Ramirez
- 381
- 6
- 20
1
vote
1 answer
Visibility synchronization at CyclicBarrier?
When using a CyclicBarrier for synchronizing threads in Java, do they synchronize non-volatile variables?
int a = 0;
int b = 0;
CyclicBarrier barrier = new CyclicBarrier(2);
/*** Thread 1 ***/
public void run() {
a = 2;
barrier.await();
…

Explicat
- 1,075
- 5
- 16
- 40
1
vote
0 answers
Hybrid semaphore/cyclic barrier needed
I'm working on a staged job system, which currently works as follows (pseudocode):
cyclicbarrier.init(numthreads)
on each thread:
for each stage s:
loop forever:
pop job from joblist[s]
if no job:
break
execute job
…

dclamage
- 33
- 3
0
votes
0 answers
Java atomicity / proper use of synchronizers & atomicity to achieve a simple use case
Working in a very simple use case challenge( just something self inflicted)
Use case: A collection, that just writes data to it. The caveat is : once it reaches a certain size (eg:25 size), the data currently in it should be flushed out( say written…

user1906450
- 517
- 1
- 6
- 19
0
votes
2 answers
Accessing output from barrier action in CyclicBarrier
I was practicing this question from oracle blog about happens before, i have a question in how to obtain/access the output of a barrier action in CyclicBarrier.
The blog…

Umar
- 1,002
- 3
- 12
- 29
0
votes
1 answer
How to make my own CyclicBarrier without use CyclicBarrier from Java Library
I am working in PacMan game for the University and basically I have to make my own CyclicBarrier, because I can't use the CyclicBarrier library from Java. This Barrier will be used to retain ghosts when they arrive to a specific position (GhostGoal)…

MdaCosta
- 49
- 1
- 10