Questions tagged [lock-free]
An umbrella term for methods and algorithms to synchronize multithreaded environments or other forms of distributed system without using locks.
97 questions
0
votes
0
answers
67
views
Lockless synchronized access to ConditionalWeakTable
I am inexperienced with writing multithreaded applications, and I am trying to wrap a ConditionalWeakTable (CWT) for use as a generalized container type. I'm aware ...
3
votes
1
answer
118
views
Multi producer/consumer lock-free queue
I would be grateful if you could review my code for a multi producer/consumer lock-free queue in C++.
I am mainly after performance improvements, but all input is welcome.
...
4
votes
3
answers
526
views
C11 zero copy lock-free triple buffer
The code is for a single producer, single consumer scenario, where the consumer only cares about the latest information shared by the producer.
This is just a simple proof of concept created for linux....
1
vote
1
answer
159
views
Implementation of a lock free queue using CompareAndSwap in Go
Here is my implementation of a lock free queue using CompareAndSwap operation.
...
1
vote
1
answer
210
views
Lock-free implementation of getAndUpdate() using atomic CAS (Compare-And-Swap) operation
We have the following class written in Kotlin Native with the new Memory Manager (which doesn't require to freeze objects):
...
3
votes
2
answers
376
views
Concurrent Handle Table
I'm writing a data structure to solve a problem related to servicing hardware interrupts. I have to translate a 64-bit pointer to a 16-bit handle and back again. Unfortunately the hardware completions ...
1
vote
1
answer
293
views
Design a thread-safe Hit Counter
I have designed a Hit Counter which can conveniently be used to design a Rate Limiter
Original question: https://leetcode.com/problems/design-hit-counter/
To make it thread safe, I used lock statement....
3
votes
1
answer
279
views
Lock-free, thread-safe trie container
This is a Trie data structure for mapping strings to integers or pointers in O(n) time. Based on the idea that we never delete anything from the container, we can perform concurrent read/write ...
22
votes
3
answers
7k
views
C++ lock-free, MPMC Ring buffer in C++20
I have some performance critical inter-thread messaging code in C++. Multiple producers, one or more consumers.
Profiling dozens of iterations of this messaging code over several years of development, ...
7
votes
1
answer
1k
views
Lock-free triple buffer
I have a single producer and single consumer, and the producer never stops, but the consumer might not keep up. There's no need to consume every item, as long as we always access the most-recently ...
4
votes
1
answer
961
views
A concurrent lock-free Linked Queue implementation
Recently I've been learning about concurrency/parallelism and I decided to implement the Michael&Scott lock-free Linked queue (PDF) as practice.
I'm not entirely sure how to test this data ...
2
votes
0
answers
648
views
Lock free ring buffer
I am hoping that someone can take a look at my implementation of a lock-free ring buffer and critique the implementation. I'm hoping that the focus can be of the correctness of the atomic operations ...
2
votes
1
answer
400
views
Is this C++11 seqlock implementation correct?
My code: https://ideone.com/DZeIZv
...
2
votes
2
answers
324
views
Lock-free multi producer logging/profiling, multi file descriptors
I am developing (for fun) a Utilities & Logging library
Can someone please help me to improve:
Github link
Pros
Thread-safe, no mutex. Use lock-free ring buffer (the idea is inherited from ...
3
votes
0
answers
73
views
implementing a mutex with capacity
Not sure this is the right place, but I'll have a try.
I'm trying to implement a mutex with capacity, which can be achieved easily with buffered channel like this:
...
2
votes
0
answers
155
views
Lock-free state machine
I've written a lock-free state machine in go and I would love to receive some feedback on it.
Writing this library my main concerns are keeping it lock-free and very light-weight (no bells and ...
6
votes
1
answer
576
views
Simple lock-free queue - multiple producers, single consumer
I have a simple lock-free queue, which supports multiple producers, but only one consumer. It is based on a constant-sized ring buffer and stores only pointers to a class and not actual instances. ...
4
votes
0
answers
100
views
C++14 AtomicRoundRobinPool for sharing a pool of keys
The idea here is that we have some resource that is relatively very expensive to generate, but once we have a bunch of them in a pool, we can keep reusing them instead of generating new ones. "HTTP ...
1
vote
1
answer
211
views
A minimalistic kind of read-copy-update class
This is a very simple read-copy-update (RCU)-inspired synchronization class:
...
2
votes
0
answers
90
views
Lock-free pooled queue
I am attempting to create a lock free pool of resources and I need the ability to access any one that is not already accessed and then return it back when I do not need it. This will happen very very ...
9
votes
2
answers
5k
views
Yet another multi-producer single consumer queue in C++17
Here's an implementation of a multi-producer single consumer queue that I wanted to use with tasks such as logging from multiple points in a program to a single sink. The implementation is inspired ...
9
votes
3
answers
6k
views
C++ lock free, single producer, single consumer queue
Assumptions for use:
push() will only ever be called by a single thread.
pop() will only ever be called by a single thread.
Requirements:
push() needs to be as fast as possible. Requirements are ...
9
votes
2
answers
2k
views
Creating a lock-free memory pool using C++11 features
I have created a thread-safe and lock-free memory pool program using C++11 features. A couple of notable features:
g_memStack is a stack that contains the memory ...
1
vote
1
answer
302
views
Passing objects atomically across threads without locks or data races for audio synchronization
I am learning about one of the hardest parts of Audio development: the synchronization between the audio thread and the GUI thread. Per the discussion here https://forum.juce.com/t/timur-doumler-...
5
votes
0
answers
941
views
A multithreaded, growable vector with immutable elements, which has wait-free reads
Disclaimer for future readers: We experimented around with a similar approach at HASH. The linked Pull Request is working.
I wrote a small vector with a few lines of unsafe Rust.
The idea is to have ...
6
votes
1
answer
1k
views
Single producer single consumer wait-free object container
I have a fast producer thread and a slow consumer thread. The consumer processes as many objects as it can and simply ignores the rest in order to not slow down the producer. Therefore, I used a one-...
10
votes
1
answer
2k
views
Snowflake Id implementation
For some time now I have maintained (and written) IdGen. It's inspired by Twitter's Snowflake project and it's intended use is to generate (roughly) incremental id's in a distributed scenario with ...
3
votes
2
answers
675
views
Customized lock-free RingBuffer
I have implemented my own lock-free ringbuffer for multiple producers multiple consumers using vector. Can you guys help me review to see if there are any problems and ways to improve?
Explanation:
...
5
votes
2
answers
1k
views
A simple lock-free queue for work stealing
I am currently reading the book C++ Concurrency in Action by Anthony Williams. In chapter 9, he implemented a lock-based work stealing queue and mentioned it is possible to implement a lock-free queue ...
0
votes
1
answer
793
views
Lock free consumer producer using memory barrier [closed]
I am looking for "complete" producer-consumer sample using C++11 memory barrier.
(I have derived following example from Jeff's article and added a line to make it complete.)
...
7
votes
1
answer
4k
views
Multiple-producer, single-consumer lock-free circular queue
I'm working on a firmware on a bare-metal ARM single core processor (Cortex M4), with no RTOS. I need to add a multiple-producer, single-consumer, lockless fixed-size circular (ring) buffer to the ...
4
votes
0
answers
286
views
An in-memory copy of the GDAX order book for an arbitrary cryptocurrency, updated in real time
GDAX is the cryptocurrency exchange owned and operated by Coinbase.
This code is intended to be the basis for an order-book-strategy trading bot.
I'd love feedback on my use of data structures, my ...
4
votes
1
answer
200
views
Lock-free Immutable ConcurrentQueue
Similar to the code review I posted last week for an agent-based immutable replacement for ConcurrentDictionary, I have also created an agent-based immutable ...
2
votes
0
answers
191
views
Lock-free statically allocated async-interrupt-safe multi-consumer double buffer
I have a single threaded embedded system with nested interrupts.
A writer interrupt will periodically update some global data structure with data.
Reader interrupts / calls from main thread will read ...
11
votes
1
answer
4k
views
Lock-free atomic shared pointer in C++14
I'm trying to write a lock-free implementation for atomic shared pointer. Basically, there are two class templates shared_ptr and ...
3
votes
0
answers
109
views
shared_mutex prototype implementation
Anyone feels to review a prototype C++11 shared_mutex implementation?
Not recursive, not protected and potentially dangerous if used incorrectly, but allegedly fast in case of many R/O less R/W ...
5
votes
1
answer
1k
views
Non blocking single producer/consumer queue with C++11 atomics
I've recently got interested in lockless programming, mainly lockless queues for job repartitions, so here I undertook a challenge of creating lockless queue for single producer and consumer.
This is ...
4
votes
2
answers
5k
views
C++ minimal threadsafe array based on std::deque
Here is a minimal example of a threadsafe array I want to build on for a timeseries application, with the following characteristics:
Ever-growing, and the already contained elements remain constant
(...
2
votes
1
answer
441
views
C++11 lock free collection similar to std::forward_list - follow-up 2
Thread safe and lock free collections are very hard to write, so I'd appreciate any feedback, especially regarding bugs. The code below is a self contained hpp, followed by some tests.
This question ...
17
votes
2
answers
6k
views
Lock-free zero-copy triple buffer
In a producer-consumer scenario sometimes we have to deal with the producer being much faster than consumer. The data loss is unavoidable, and we are OK with it, as long as the consumer always has the ...
9
votes
3
answers
2k
views
Naive lock free work stealing queue
Recently, I read a article about work stealing queue Job System 2.0: Lock-Free Work Stealing – Part 3: Going lock-free, and this is my c++11 naive implementation based on my understand of c++11 ...
4
votes
1
answer
3k
views
4
votes
0
answers
78
views
Fast lock implementation using pipes only
For fun I wanted to create a lock implementation that was about as fast as one using futexes but that used used pipes instead and that queues waiters in user space instead of in-kernel. For the queue ...
0
votes
2
answers
4k
views
Concurrent Stack with blocking and non-blocking methods
I wrote it this just for learning. Is there holes at this code?
...
2
votes
2
answers
315
views
Thread-efficient nonce generations
I need to create unique nonces for cryptographic purposes in a library that I am writing. If the nonces ever fail to be unique, the consequences may be up to and including remote execution of ...
2
votes
0
answers
115
views
SPSC job scheduling with lockfree workqueue and abortable jobs
Since I had not found exactly what I was looking for I wrote some simple workqueue-based job system myself that is based on boost's lock-free queue. It is supposed to be used in some GUI application ...
3
votes
0
answers
714
views
Concurrent resizable ring buffer
I'm trying to find the fastest way to enqueue and dequeue items concurrently in Go.
There are some restrictions:
it needs to be unbounded
Memory allocation should be low
Multiple producers
(Single ...
4
votes
1
answer
107
views
A scalable lock-free channel
Here's my lock-free channel impl lfchan,
I didn't want to copy/paste the code here since it is multiple files.
I'm trying to get an idea of what can be improved or if there are any bugs in it.
chan....
7
votes
1
answer
2k
views
Lock-free multi-producer multi-consumer queue
I'm looking for some feedback on my lock-free queue, based on Disruptor, mainly for any potential concurrency issues, such as where I need additional fences. It looks correct to me, and I can't seem ...
4
votes
1
answer
4k
views
Lock-free list in C++
I tried to write a lock-free list in C++. Unfortunately, the performance compared to an std::list secured with a simple mutex is bad.
What do you think? Are there ...