lock-free

Looking for critique of my thread safe, lock-free queue implementation

◇◆丶佛笑我妖孽 提交于 2019-11-30 21:44:45
So, I've written a queue, after a bit of research. It uses a fixed-size buffer, so it's a circular queue. It has to be thread-safe, and I've tried to make it lock-free. I'd like to know what's wrong with it, because these kinds of things are difficult to predict on my own. Here's the header: template <class T> class LockFreeQueue { public: LockFreeQueue(uint buffersize) : buffer(NULL), ifront1(0), ifront2(0), iback1(0), iback2(0), size(buffersize) { buffer = new atomic <T>[buffersize]; } ~LockFreeQueue(void) { if (buffer) delete[] buffer; } bool pop(T* output); bool push(T input); private:

What's the difference between lockless and lockfree?

无人久伴 提交于 2019-11-30 16:56:01
问题 In some articles about algorithm, some use the word lockfree , and some use lockless . What's the difference between lockless and lockfree ? Thanks! Update http://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-dpdk-programmers-guide.pdf section 5.2 --"Lockless Ring Buffer in Linux*", it's a example of use word "lockless" 回答1: An algorithm is lock-free if it satisfies that when the program threads are run sufficiently long at least one of the threads makes progress (for some

Average latency of atomics cmpxchg instructions on Intel Cpus

你。 提交于 2019-11-30 15:18:31
问题 I am looking for some reference on average latencies for lock cmpxchg instruction for various intel processors. I am not able to locate any good reference on the topic and any reference would greatly help. Thanks. 回答1: There are few, if any, good references on this because there is so much variation. It depends on basically everything including bus speed, memory speed, processor speed, processor count, surrounding instructions, memory fencing and quite possibly the angle between the moon and

Does an optimistic lock-free FIFO queue implementation exist?

Deadly 提交于 2019-11-30 14:56:46
问题 Is there any C++ implementation (source codes) of "optmistic approach to lock-free FIFO queues" algorithm? 回答1: Herb Sutter covered just such a queue as part of his Effective Concurency column in Dr. Dobbs Journal. Writing Lock-Free Code: A Corrected Queue 回答2: I want to conclude the answer given by greyfade , which is based on http://www.drdobbs.com/high-performance-computing/212201163 (the last part of the article), the optimized code would be (with some modification to suit my naming and

Average latency of atomics cmpxchg instructions on Intel Cpus

为君一笑 提交于 2019-11-30 13:53:23
I am looking for some reference on average latencies for lock cmpxchg instruction for various intel processors. I am not able to locate any good reference on the topic and any reference would greatly help. Thanks. Zooba There are few, if any, good references on this because there is so much variation. It depends on basically everything including bus speed, memory speed, processor speed, processor count, surrounding instructions, memory fencing and quite possibly the angle between the moon and Mt Everest... If you have a very specific application, as in, known (fixed) hardware, operating

Does an optimistic lock-free FIFO queue implementation exist?

人盡茶涼 提交于 2019-11-30 13:08:48
Is there any C++ implementation (source codes) of " optmistic approach to lock-free FIFO queues" algorithm ? Herb Sutter covered just such a queue as part of his Effective Concurency column in Dr. Dobbs Journal. Writing Lock-Free Code: A Corrected Queue I want to conclude the answer given by greyfade , which is based on http://www.drdobbs.com/high-performance-computing/212201163 (the last part of the article), the optimized code would be (with some modification to suit my naming and coding convention) : ` template <typename T> class LFQueue { private: struct LFQNode { LFQNode( T* val ) : value

Any single-consumer single-producer lock free queue implementation in C?

↘锁芯ラ 提交于 2019-11-30 10:51:13
问题 I'm writing a program with a consumer thread and a producer thread, now it seems queue synchronization is a big overhead in the program, and I looked for some lock free queue implementations, but only found Lamport's version and an improved version on PPoPP '08: enqueue_nonblock(data) { if (NULL != buffer[head]) { return EWOULDBLOCK; } buffer[head] = data; head = NEXT(head); return 0; } dequeue_nonblock(data) { data = buffer[tail]; if (NULL == data) { return EWOULDBLOCK; } buffer[tail] = NULL

ForkJoinPool stalls during invokeAll/join

核能气质少年 提交于 2019-11-30 09:59:08
I try to use a ForkJoinPool to parallelize my CPU intensive calculations. My understanding of a ForkJoinPool is, that it continues to work as long as any task is available to be executed. Unfortunately I frequently observed worker threads idling/waiting, thus not all CPU are kept busy. Sometimes I even observed additional worker threads. I did not expect this, as I strictly tried to use non blocking tasks. My observation is very similar to those of ForkJoinPool seems to waste a thread . After debugging a lot into ForkJoinPool I have a guess: I used invokeAll() to distribute work over a list of

Looking for critique of my thread safe, lock-free queue implementation

烈酒焚心 提交于 2019-11-30 05:33:59
问题 So, I've written a queue, after a bit of research. It uses a fixed-size buffer, so it's a circular queue. It has to be thread-safe, and I've tried to make it lock-free. I'd like to know what's wrong with it, because these kinds of things are difficult to predict on my own. Here's the header: template <class T> class LockFreeQueue { public: LockFreeQueue(uint buffersize) : buffer(NULL), ifront1(0), ifront2(0), iback1(0), iback2(0), size(buffersize) { buffer = new atomic <T>[buffersize]; }

Any single-consumer single-producer lock free queue implementation in C?

两盒软妹~` 提交于 2019-11-29 22:39:41
I'm writing a program with a consumer thread and a producer thread, now it seems queue synchronization is a big overhead in the program, and I looked for some lock free queue implementations, but only found Lamport's version and an improved version on PPoPP '08: enqueue_nonblock(data) { if (NULL != buffer[head]) { return EWOULDBLOCK; } buffer[head] = data; head = NEXT(head); return 0; } dequeue_nonblock(data) { data = buffer[tail]; if (NULL == data) { return EWOULDBLOCK; } buffer[tail] = NULL; tail = NEXT(tail); return 0; } Both versions require a pre-allocated array for the data, my question