barrier

memory barrier and atomic_t on linux

两盒软妹~` 提交于 2019-11-29 01:43:06
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); //#3 What is the semantics of this code snippet? Does it make sure #1 executes before #3 by #2. But I am a litter bit confused, becasue #A In 64 bit platform, atomic64_read macro is expanded to used = (&g_variable->used)->counter // where counter is volatile. In 32 bits platform, it was converted to use lock cmpxchg8b . I assume these two have the same semantic, and for 64 bits version, I

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

帅比萌擦擦* 提交于 2019-11-28 23:46:31
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 reader/writer combination which results in a reader never seeing the written value, under certain very specific conditions--dedicated CPU, process attached to CPU, optimizer turned all the way up, no other work done in the loop--so the arrows do point in that direction, but I'm not entirely sure about the cost of spinning through a memory barrier.)

Implementing boost::barrier in C++11

为君一笑 提交于 2019-11-28 08:26:17
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 of them finish. The basic idea is that the main loop gives the go order (boost::barrier .wait()) and waits for the result with the same function. I had implemented in a different project a custom made Barrier based on the Boost version and everything worked perfectly. Implementation is as follows: Barrier.h: class Barrier { public: Barrier(unsigned

How can barriers be destroyable as soon as pthread_barrier_wait returns?

我与影子孤独终老i 提交于 2019-11-27 23:46:14
问题 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 be valid to destroy a barrier as soon as pthread_barrier_wait returns, as per the above linked question. (Normally, the thread that got PTHREAD_BARRIER_SERIAL_THREAD , or a "special" thread that already considered itself "responsible" for the

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

你说的曾经没有我的故事 提交于 2019-11-27 16:14:10
问题 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, but which fails for process-shared barriers. We later worked through some ideas, but never reached a satisfactory conclusion, and didn't even begin to get into resource failure cases. Is it possible on Linux to make a barrier that meets these

memory barrier and atomic_t on linux

微笑、不失礼 提交于 2019-11-27 16:13:03
问题 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); //#3 What is the semantics of this code snippet? Does it make sure #1 executes before #3 by #2. But I am a litter bit confused, becasue #A In 64 bit platform, atomic64_read macro is expanded to used = (&g_variable->used)->counter // where counter is volatile. In 32 bits platform, it was

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

大兔子大兔子 提交于 2019-11-27 15:16:19
问题 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 reader/writer combination which results in a reader never seeing the written value, under certain very specific conditions--dedicated CPU, process attached to CPU, optimizer turned all the way up, no other work done in the loop--so the arrows do

Implementing boost::barrier in C++11

家住魔仙堡 提交于 2019-11-27 01:51:42
问题 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 of them finish. The basic idea is that the main loop gives the go order (boost::barrier .wait()) and waits for the result with the same function. I had implemented in a different project a custom made Barrier based on the Boost version and

Implementing an N process barrier using semaphores

ε祈祈猫儿з 提交于 2019-11-26 18:07:08
问题 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 processes to reach their given point. You have the following ops available: init(sem,value), wait(sem) and signal(sem) N is an arbitrary number. I can make it so that it works for a given number of processes, but not for any number. Any ideas? It's OK