Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [lock-free]

An umbrella term for methods and algorithms to synchronize multithreaded environments or other forms of distributed system without using locks.

Filter by
Sorted by
Tagged with
1 vote
0 answers
57 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 ...
monkey0506's user avatar
3 votes
1 answer
109 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. ...
Mr. Orange's user avatar
4 votes
3 answers
514 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....
mausys's user avatar
  • 49
1 vote
1 answer
147 views

Implementation of a lock free queue using CompareAndSwap in Go

Here is my implementation of a lock free queue using CompareAndSwap operation. ...
Tauseef Ahmad's user avatar
1 vote
1 answer
195 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): ...
Volo's user avatar
  • 111
3 votes
2 answers
371 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 ...
BlamKiwi's user avatar
  • 181
1 vote
1 answer
274 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....
Daniel B's user avatar
  • 146
3 votes
1 answer
271 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 ...
CaptainCodeman's user avatar
1 vote
0 answers
170 views

Lock-Free Single Reader/Single Writer Lamport Queue

I've created a lock-free lamport queue in rust. My code should be clear enough that you won't need to understand a lamport queue before reading it, but if you'd like a reference, this paper give a ...
thesecretmaster's user avatar
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, ...
Ash's user avatar
  • 364
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 ...
Toby Speight's user avatar
  • 75.7k
4 votes
1 answer
921 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 ...
chromaticc's user avatar
1 vote
0 answers
626 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 ...
Pete's user avatar
  • 11
2 votes
1 answer
385 views

Is this C++11 seqlock implementation correct?

My code: https://ideone.com/DZeIZv ...
gavv's user avatar
  • 121
2 votes
2 answers
318 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 ...
LongLT's user avatar
  • 121
3 votes
0 answers
69 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: ...
zhiqiangxu's user avatar
2 votes
0 answers
147 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 ...
Eyal's user avatar
  • 309
6 votes
1 answer
570 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. ...
Perl99's user avatar
  • 69
4 votes
0 answers
96 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 ...
Quuxplusone's user avatar
  • 19.4k
1 vote
1 answer
209 views

A minimalistic kind of read-copy-update class

This is a very simple read-copy-update (RCU)-inspired synchronization class: ...
Ignorant's user avatar
  • 119
2 votes
0 answers
87 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 ...
Christopher Silvas's user avatar
8 votes
1 answer
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 ...
Vilas Chitrakaran's user avatar
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 ...
Phi's user avatar
  • 93
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 ...
water's user avatar
  • 93
1 vote
1 answer
298 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-...
MatkatMusic's user avatar
5 votes
0 answers
935 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 ...
Tim Diekmann's user avatar
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-...
purefanatic's user avatar
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 ...
RobIII's user avatar
  • 195
3 votes
2 answers
668 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: ...
interceptwind's user avatar
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 ...
Elaine's user avatar
  • 51
0 votes
1 answer
788 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.) ...
endless limit's user avatar
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 ...
vgru's user avatar
  • 1,388
4 votes
0 answers
285 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 ...
feuGene's user avatar
  • 363
4 votes
1 answer
198 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 ...
Aaron M. Eshbach's user avatar
2 votes
0 answers
184 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 ...
user80551's user avatar
  • 121
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 ...
Lingxi's user avatar
  • 818
3 votes
0 answers
107 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 ...
Emanuele's user avatar
  • 240
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 ...
FanciestBanana's user avatar
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 (...
davidhigh's user avatar
  • 538
2 votes
1 answer
436 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 ...
Brent's user avatar
  • 451
1 vote
0 answers
834 views

Lock-free segmented shared memory buffer in C++

Summary The code operates three memory mapped file segments: just finished currently active next to write Potentially slow operations of closing just finished and opening next to write are done in ...
bobah's user avatar
  • 361
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 ...
vnp's user avatar
  • 56.5k
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 ...
benlong's user avatar
  • 203
4 votes
1 answer
3k views

Lock-free FIFO queue implementation

...
ShadowStar's user avatar
4 votes
0 answers
74 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 ...
Ms. Molly Stewart-Gallus's user avatar
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? ...
gstackoverflow's user avatar
2 votes
2 answers
311 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 ...
Demi's user avatar
  • 325
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 ...
IceFire's user avatar
  • 183
3 votes
0 answers
704 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 ...
Roger Johansson's user avatar
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....
OneOfOne's user avatar
  • 355