Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a production ready lock-free queue or hash implementation in C++ [closed]

Tags:

c++

stl

lock-free

I ve been googling quite a bit for a lock-free queue in C++. I found some code and some trials - but nothing that i was able to compile. A lock-free hash would also be welcome.

SUMMARY: So far i have no positive answer. There is no "production ready" library, and amazingly none of the existent libraries complies to the API of STL containers.

like image 425
RED SOFT ADAIR Avatar asked Jul 22 '09 09:07

RED SOFT ADAIR


People also ask

What is a lock free queue?

Lock-free queue is a queue applying to concurrency but without locking. When using lock-free queue, slow or stopped processes do not prevent other processes from accessing data in it. Lock-free queue has two main interfaces just like normal queue: Enqueue.

What are lock free data structures?

A data structure provides lock-freedom if, at any time, at least one thread can proceed. All other threads may be starving. The difference to obstruction-freedom is that there is at least one non-starving thread even if no threads are suspended.


2 Answers

As of 1.53, boost provides a set of lock free data structures, including queues, stacks and single-producer/single-consumer queues (i.e. ring buffers).

like image 180
Nova Avatar answered Sep 22 '22 18:09

Nova


The starting point would be either of Herb Sutter's DDJ articles for either a single producer and consumer or multiple ones. The code he gives (in-line starting on the second page of each article) uses the C++0x style atomic<T> template type; which you can imitate using the Boost interprocess library.

The boost code is buried in the depths of the interprocess library, but having read through the appropriate header file (atomic.hpp) the implementations for the necessary compare-and-swap operations on the systems I am familiar with look sound.

like image 20
Steve Gilham Avatar answered Sep 20 '22 18:09

Steve Gilham