lock-free

Is a lock (wait) free doubly linked list possible?

六眼飞鱼酱① 提交于 2019-11-28 19:51:09
Asking this question with C# tag, but if it is possible, it should be possible in any language. Is it possible to implement a doubly linked list using Interlocked operations to provide no-wait locking? I would want to insert, add and remove, and clear without waiting. Unknown A simple google search will reveal many lock-free doubly linked list papers. However, they are based on atomic CAS (compare and swap). I don't know how atomic the operations in C# are, but according to this website http://www.albahari.com/threading/part4.aspx C# operations are only guaranteed to be atomic for reading and

Lock Free Queue — Single Producer, Multiple Consumers

老子叫甜甜 提交于 2019-11-28 18:23:23
I am looking for a method to implement lock-free queue data structure that supports single producer, and multiple consumers. I have looked at the classic method by Maged Michael and Michael Scott (1996) but their version uses linked lists. I would like an implementation that makes use of bounded circular buffer. Something that uses atomic variables? On a side note, I am not sure why these classic methods are designed for linked lists that require a lot of dynamic memory management. In a multi-threaded program, all memory management routines are serialized. Aren't we defeating the benefits of

How can I write a lock free structure?

ぐ巨炮叔叔 提交于 2019-11-28 18:12:11
In my multithreaded application and I see heavy lock contention in it, preventing good scalability across multiple cores. I have decided to use lock free programming to solve this. How can I write a lock free structure? Short answer is: You cannot. Long answer is: If you are asking this question, you do not probably know enough to be able to create a lock free structure. Creating lock free structures is extremely hard, and only experts in this field can do it. Instead of writing your own, search for an existing implementation. When you find it, check how widely it is used, how well is it

How to achieve lock-free, but blocking behavior?

久未见 提交于 2019-11-28 16:52:47
问题 I'm implementing a lock-free single producer single consumer queue for an intensive network application. I have a bunch of worker threads receiving work in their own separate queues, which they then dequeue and process. Removing the locks from these queues have greatly improved the performance under high load, but they no longer block when the queues are empty , which in turn causes the CPU usage to skyrocket. How can I efficiently cause a thread to block until it can successfully dequeue

Does a multiple producer single consumer lock-free queue exist for c++? [closed]

最后都变了- 提交于 2019-11-28 16:43:26
The more I read the more confused I become... I would have thought it trivial to find a formally correct mpsc queue implemented in c++. Every time I find another stab at it, further research seems to suggest there are issues such as ABA or other subtle race conditions. Many talk of the need for garbage collection. This is something I want to avoid. Is there an accepted correct open source implementation out there? bronekk You may want to check disruptor; it's available in C++ here: http://lmax-exchange.github.io/disruptor/ You can also find explanation how it works here on stackoverflow

Lock-free multi-threading is for real threading experts

眉间皱痕 提交于 2019-11-28 14:56:22
I was reading through an answer that Jon Skeet gave to a question and in it he mentioned this: As far as I'm concerned, lock-free multi-threading is for real threading experts, of which I'm not one. Its not the first time that I have heard this, but I find very few people talking about how you actually do it if you are interested in learning how to write lock-free multi-threading code. So my question is besides learning all you can about threading, etc where do you start trying to learn to specifically write lock-free multi-threading code and what are some good resources. Cheers Andras Vass

Atomic operations for lock-free doubly linked list

℡╲_俬逩灬. 提交于 2019-11-28 10:35:34
I am writing a lock-free doubly linked list based on these papers: "Efficient and Reliable Lock-Free Memory Reclamation Based on Reference Counting" Anders Gidenstam,Member, IEEE,Marina Papatriantafilou, H˚ akan Sundell and Philippas Tsigas "Lock-free deques and doubly linked lists" Håkan Sundell, Philippas Tsigas For this question we can put aside first paper. In this paper, they use a smart way for storing a deletion flag and a pointer in a word. (More info here ) Pseudo code for this section in the paper: union Link : word (p,d): {pointer to Node, boolean} structure Node value: pointer to

/boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value)

时光怂恿深爱的人放手 提交于 2019-11-28 08:18:07
问题 I'm trying to substitute boost::lockfree::queue for std::queue in this file https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp I've added #include <boost/lockfree/queue.hpp> ; changed line 130 , std::queue<action> m_actions; , to boost::lockfree::queue<action> m_actions; ; removed all lines having to do with locking; and changed line 103 , m_actions.pop(); , to m_actions.pop(a); . I get these errors when I scons broadcast_server_lockfree in

C++ atomic operations for lock-free structures

微笑、不失礼 提交于 2019-11-28 06:02:40
I'm implementing a lock-free mechanism using atomic (double) compare and swap instructions e.g. cmpxchg16b I'm currently writing this in assembly and then linking it in. However, I wondered if there was a way of getting the compiler to do this for me automatically? e.g. surround code block with 'atomically' and have it go figure it out how to implement the code as an atomic instruction in the underlying processor architecture (or generate an error at compile time if the underlying arch does not support it)? P.S. I know that gcc has some built-ins (at least for CAS) http://gcc.gnu.org

Dependent loads reordering in CPU

痞子三分冷 提交于 2019-11-28 01:14:51
I have been reading Memory Barriers: A Hardware View For Software Hackers , a very popular article by Paul E. McKenney. One of the things the paper highlights is that, very weakly ordered processors like Alpha, can reorder dependent loads which seems to be a side effect of partitioned cache Snippet from the paper: 1 struct el *insert(long key, long data) 2 { 3 struct el *p; 4 p = kmalloc(sizeof(*p), GPF_ATOMIC); 5 spin_lock(&mutex); 6 p->next = head.next; 7 p->key = key; 8 p->data = data; 9 smp_wmb(); 10 head.next = p; 11 spin_unlock(&mutex); 12 } 13 14 struct el *search(long key) 15 { 16