lock-free

Circular lock-free buffer

非 Y 不嫁゛ 提交于 2019-11-26 10:06:02
问题 I\'m in the process of designing a system which connects to one or more stream of data feeds and do some analysis on the data than trigger events based on the result. In a typical multi-threaded producer/consumer setup, I will have multiple producer threads putting data into a queue, and multiple consumer threads reading the data, and the consumers are only interested in the latest data point plus n number of points. The producer threads will have to block if slow consumer can not keep up,

Shared-memory IPC synchronization (lock-free)

早过忘川 提交于 2019-11-26 04:45:30
问题 Consider the following scenario: Requirements: Intel x64 Server (multiple CPU-sockets => NUMA) Ubuntu 12, GCC 4.6 Two processes sharing large amounts of data over (named) shared-memory Classical producer-consumer scenario Memory is arranged in a circular buffer (with M elements) Program sequence (pseudo code): Process A (Producer): int bufferPos = 0; while( true ) { if( isBufferEmpty( bufferPos ) ) { writeData( bufferPos ); setBufferFull( bufferPos ); bufferPos = ( bufferPos + 1 ) % M; } }

Lock-free Progress Guarantees

六眼飞鱼酱① 提交于 2019-11-26 04:25:50
问题 Anecdotally, I\'ve found that a lot of programmers mistakenly believe that \"lock-free\" simply means \"concurrent programming without mutexes\". Usually, there\'s also a correlated misunderstanding that the purpose of writing lock-free code is for better concurrent performance. Of course, the correct definition of lock-free is actually about progress guarantees . A lock-free algorithm guarantees that at least one thread is able to make forward progress regardless of what any other threads

How can I implement ABA counter with c++11 CAS?

不想你离开。 提交于 2019-11-26 01:08:59
问题 I am implementing a lock-free queue based on this algorithm, which uses a counter to solve the ABA problem. But I don\'t know how to implement this counter with c++11 CAS. For example, from the algorithm: E9: if CAS(&tail.ptr->next, next, <node, next.count+1>) It is an atomic operation, meaning if tail.ptr->next is equal to next , let tail.ptr->next point to node and simultaneously (atomically) make next.count+1 . However, using C++11 CAS, I can only implement: std::atomic_compare_exchange