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
37
votes
3 answers

Real-life use cases of barriers (DSB, DMB, ISB) in ARM

I understand that DSB, DMB, and ISB are barriers for prevent reordering of instructions. I also can find lots of very good explanations for each of them, but it is pretty hard to imagine the case that I have to use them. Also, from the open source…
jaeyong
  • 8,951
  • 14
  • 50
  • 63
27
votes
4 answers

Implementing an N process barrier using semaphores

I'm currently training for an OS exam with previous iterations and I came across this: Implement a "N Process Barrier", that is, making sure that each process out of a group of them waits, at some point in its respective execution, for the other…
19
votes
4 answers

Implementing boost::barrier in C++11

I've been trying to get a project rid of every boost reference and switch to pure C++11. At one point, thread workers are created which wait for a barrier to give the 'go' command, do the work (spread through the N threads) and synchronize when all…
h4lc0n
  • 2,730
  • 5
  • 29
  • 41
16
votes
3 answers

In OpenCL, what does mem_fence() do, as opposed to barrier()?

Unlike barrier() (which I think I understand), mem_fence() does not affect all items in the work group. The OpenCL spec says (section 6.11.10), for mem_fence(): Orders loads and stores of a work-item executing a kernel. (so it applies to a single…
andrew cooke
  • 45,717
  • 10
  • 93
  • 143
13
votes
3 answers

Dispatch_barrier_async and serial queue in GCD, what're differences between them?

I found that the working mechanism of dispatch_barrier_async is that it is only executed once all of the blocks previously added to the queue have been completed. It works similar to the serial queue. Therefore, I do not distinguish what the…
Binh Le
  • 353
  • 3
  • 11
12
votes
2 answers

memory barrier and atomic_t on linux

Recently, I am reading some Linux kernel space codes, I see this uint64_t used; uint64_t blocked; used = atomic64_read(&g_variable->used); //#1 barrier(); //#2 blocked = atomic64_read(&g_variable->blocked);…
Chang
  • 3,953
  • 2
  • 30
  • 43
12
votes
2 answers

How can barriers be destroyable as soon as pthread_barrier_wait returns?

This question is based on: When is it safe to destroy a pthread barrier? and the recent glibc bug report: http://sourceware.org/bugzilla/show_bug.cgi?id=12674 I'm not sure about the semaphores issue reported in glibc, but presumably it's supposed to…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
11
votes
3 answers

Can a correct fail-safe process-shared barrier be implemented on Linux?

In a past question, I asked about implementing pthread barriers without destruction races: How can barriers be destroyable as soon as pthread_barrier_wait returns? and received from Michael Burr with a perfect solution for process-local barriers,…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
11
votes
2 answers

What is the C++11 atomic API equivalent to ```__asm__ volatile("" ::: "memory")```

A codebase has a COMPILER_BARRIER macro defined as __asm__ volatile("" ::: "memory"). The intent of the macro is to prevent the compiler from re-ordering reads and writes across the barrier. Note that this is explicitly a compiler barrier, and not a…
acm
  • 12,183
  • 5
  • 39
  • 68
10
votes
3 answers

Do spin locks always require a memory barrier? Is spinning on a memory barrier expensive?

I wrote some lock-free code that works fine with local reads, under most conditions. Does local spinning on a memory read necessarily imply I have to ALWAYS insert a memory barrier before the spinning read? (To validate this, I managed to produce a…
blais
  • 687
  • 7
  • 9
10
votes
1 answer

Why do separate arrive and wait exist in C++20 barrier?

C++20 std::barrier has arrive_and_wait method, which is what pretty much every synchronization barrier implementation has. But it also has separate arrive and wait. Why do these functions exist?
Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79
10
votes
3 answers

How to implement a Thread Safe HashTable (PhoneBook) Data Structure in Swift?

I am trying to implement a Thread-Safe PhoneBook object. The phone book should be able to add a person, and look up a person based on their name and phoneNumber. From an implementation perspective this simply involves two hash tables, one…
10
votes
1 answer

Are Pthread Barriers in C Reusable?

So I know that you can create barriers in C to control the flow of a threaded program. You can initialize the barrier, have your threads use it, and then destroy it. However, I am unsure whether or not the same barrier can be reused (say if it were…
Callahan
  • 101
  • 1
  • 4
10
votes
2 answers

How is barrier implemented in message passing systems?

What I understand is, that one master process sends a message to all other processes. All the other processes in return send a message to the master process. Would this be enough for a barrier to work? If not, then what more is needed?
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
8
votes
1 answer

Changing code from Sequential Consistency to a less stringent ordering in a barrier implementation

I came across this code for a simple implementation of a barrier (for code that can't use std::experimental::barrier in C++17 or std::barrier in C++20) in C++ Concurrency in Action book. [Edit] A barrier is a synchronization mechanism where a group…
user17799869
  • 125
  • 9
1
2 3
16 17