All Questions
Tagged with lock-free multithreading
36 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.
...
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):
...
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....
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, ...
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 ...
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 ...
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 ...
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.)
...
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 ...
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
(...
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 ...
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 ...
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 ...
3
votes
2
answers
151
views
Single reader - multiple writer waitable lock-free unreliably ordered stack
The main body of code is located here. In the code linted_error is a platform specific type for error codes. As well, as an optimization the code can use Linux ...
2
votes
0
answers
432
views
Implementation of a lock-free fixed-sized allocator - follow-up - with commented code
The following implementation of a lock-free fixed-size allocator is a follow-up of:
Implementation of a lock-free fixed-sized allocator
§1 - Introduction
The purpose is self-learning of atomic ...
12
votes
2
answers
2k
views
Implementation of a lock-free fixed-sized allocator
This question now has a follow-up:
Implementation of a lock-free fixed-sized allocator - follow-up - with commented code
I've tried implementing a lock-free fixed-size allocator while trying to ...
4
votes
1
answer
183
views
Lock-free bounded stack atomics
I was thinking about using very basic bounded (preallocated) stack to keep track of my threads IDs in correct LIFO order. I was wondering if my implementation is thread safe:
...
4
votes
2
answers
5k
views
ArrayBlockingQueue: concurrent put and take
I have implemented an ArrayBlockingQueue (put and take) on the lines of LinkedBlockingQueue i.e using two locks so that my take ...
5
votes
2
answers
4k
views
Lock-free multiple producer single consumer message queue
For a while now I've been after a lock-free, simple and scalable implementation of a multiple producer, single consumer queue for delegates in C#. I think I finally have it. I've run basic tests on it ...
5
votes
1
answer
3k
views
Single consumer and single producer lock-free circular buffer
I'm pretty new to multithreading. The code below is a simple implementation of a single consumer/single producer circular buffer that does not use any locking, that I wrote for fun.
The question is,...
5
votes
1
answer
2k
views
Lockfree ThreadPool implementation
How could this template class ThreadPool be improved?
I use Boost queue to keep std::function's numbers from ...
5
votes
1
answer
861
views
CountdownLatch Thread-Safety Check
I've written this class as an exercise for a synchronization construct to be used across multiple threads.
The intent is to have worker threads Increment() it, do ...
8
votes
2
answers
3k
views
Lockless Queue Multiple-Reader Singler-Writer in C++
I wrote a lockless queue for sending small objects from a single thread to a random worker thread.
Assumptions:
x86/x86_64 compiled with GCC
one thread may Write(), multiple threads may Read()
...
8
votes
1
answer
819
views
Low-lock Multi-threading Implementation
I'm designing in my spare time a game engine (for fun, not so much for profit, haha). I wanted to design the 'core pipeline' as efficiently as possible. Having a quad-core CPU, I decided to take ...
3
votes
2
answers
326
views
Multi producer/consumers lockfree list
As per a similar question, following a lockfree list implementation. Note that this list has a pre-defined maximum set of elements which can be inserted (N argument ...
4
votes
1
answer
415
views
Multi producer/consumers lockfree stack
Can you please take a look at the following x86-64 C++ code which should implement a multi consumer/produce lockfree stack? Do you think I have missed anything?
...
2
votes
1
answer
103
views
Simple Freelock collection
I wrote simple lock-free collection class for saving items from multithreading code. I did it just for fun and experience. Can you check my code for potentially problems please?
...
2
votes
1
answer
3k
views
Publisher/Consumer thread-safe lock-free queue with a single publisher/consumer
The code above is a implementation of a lock-free queue that makes the assumption that there is exactly one Consumer thread and one Producer thread. This works as intended? The memory barriers is used ...
15
votes
2
answers
1k
views
Lock-free cache oblivious n-body algorithm
I'm currently looking at, from a rather high level, the parallelization of the gravity calculation in an N-body simulation for approximating a solution to the N-body problem.
The simple form of the ...
49
votes
5
answers
15k
views
Thread-Safe and Lock-Free - Queue Implementation
I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently.
Would you ...