Questions tagged [barrier]

A barrier is a synchronization method for a group of threads or processes and means they must stop at this point and cannot proceed until all other threads/processes reach this barrier.

A barrier is a synchronization method for a group of threads or processes and means they must stop at this point and cannot proceed until all other threads/processes reach this barrier.

References

252 questions
8
votes
4 answers

Barrier operations in NSOperationQueue

How can we implement dispatch_barrier_async's equivalent behavior using NSOperationQueue or any user-defined data-structure based on NSOperationQueue? The requirement is, whenever a barrier operation is submitted it should wait until all non-barrier…
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
2 answers

gcc and cpu_relax, smb_mb, etc.?

I've been reading on compiler optimizations vs CPU optimizations, and volatile vs memory barriers. One thing which isn't clear to me is that my current understanding is that CPU optimizations and compiler optimizations are orthogonal. I.e. can occur…
YSK
  • 1,572
  • 10
  • 19
7
votes
1 answer

Pthread Barrier vs. Loop Join

So my question in C is: what is basically the differences (maybe pros and cons) of using a pthread barrier (init and wait..etc) compared to using the pthread Join in a loop. So say I created 10 threads in a loop, and then later at the place of where…
JoHa
  • 1,989
  • 10
  • 28
  • 42
7
votes
2 answers

Can this parallelism be implemented in OpenCL

This is my first post. I'll try to keep it short because I value your time. This community has been incredible to me. I am learning OpenCL and want to extract a little bit of parallelism from the below algorithm. I will only show you the part that I…
Shoomla
  • 131
  • 6
6
votes
1 answer

Barriers and synchronization points with non-atomic variables - data race?

Consider the following program: int i{0}; std::experimental::barrier b{2}; int main() { std::thread t0{[] { b.arrive_and_wait(); std::cout << i << '\n'; }}; std::thread t1{[] { i = 2; …
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
5
votes
1 answer

C++ std::barrier as class member

How do you store an std::barrier as a class member, Because the completion function can be a lambda, you can't type it properly, and using an std::function< void(void) noexcept > won't work either as std::function does not seem to support the…
Sam Coutteau
  • 111
  • 5
5
votes
1 answer

Does Java monitor's wait set has a priority over entry set?

I would like to ask you a question related to multithreading in Java. I have a monitor and multiple threads are eager to own it. Also inside the critical section this.wait() is invoked based on some conditions. AFAIK, the monitor has 2 sets of…
Pasha
  • 1,768
  • 6
  • 22
  • 43
5
votes
1 answer

Does immutable object need to be accessed across memory barrier in C#?

When an immutable object is new'ed up in one thread, and shared in second thread (say as a field of shared object), shouldn't second thread synchronize? Thread1: ========= x = new SomeObject() Thread2 ========= if (x != null) …
drr
  • 91
  • 1
  • 4
5
votes
1 answer

Reusable Barrier Algorithm

I'm looking into the Reusable Barrier algorithm from the book "The Little Book Of Semaphores" (archived here). The puzzle is on page 31 (Basic Synchronization Patterns/Reusable Barrier), and I have come up with a 'solution' (or not) which differs…
soulseekah
  • 8,770
  • 3
  • 53
  • 58
5
votes
2 answers

How can I wait for an unknown number of Rust threads to complete without using tracking handles?

What are some good ways to adapt this Barrier example to handle two differences: the number of items is not known in advance (for example, in the case where splitting a large file into lines) without tracking thread handles (e.g. without using the…
David J.
  • 31,569
  • 22
  • 122
  • 174
5
votes
1 answer

Why does MPI_Barrier cause a segmentation fault in C++

I have reduced my program to the following example: #include int main(int argc, char * argv[]) { int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); …
jboss
  • 51
  • 2
5
votes
1 answer

Share Barrier across threads in D

I'm having a heck of a time trying to get the barrier sync in D to work properly. I'm currently not getting any compiler errors, however every time it reaches the barrier I get a segmentation fault. Here's basically what I have: import…
jdeters
  • 53
  • 3
4
votes
2 answers

Synchronize threads for pthread_cond_broadcast call

I have a simple application with a "manager" thread that spawns ten simple "worker" threads. I want all of the "worker" threads to block on the same condition variable (ie: condvar), and I want to manually signal all ten threads to wake up at the…
Cloud
  • 18,753
  • 15
  • 79
  • 153
4
votes
0 answers

Barrier deadlocks in GCC 11.1.0

Consider the following C++ code: #include #include #include #include int main() { constexpr unsigned N = 2; std::barrier barrier(N); auto const run = [&barrier]() { std::string buff; …
Koosha
  • 1,492
  • 7
  • 19
1
2
3
16 17