lockless | Collection of lockfree doodads | Caching library
kandi X-RAY | lockless Summary
kandi X-RAY | lockless Summary
Collection of random lockfree doodads that exist for the sole purpose of amusing/frustrating me. Current doodads worthy of notice:. Small note, some of these algorithms contains some pretty glaring performance flaws (eg. both epochs in Rcu are stored on the same cache line). I’m intentionally leaving these as is so that I can mesure the effect of fixing them at a later undisclosed point in time.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lockless
lockless Key Features
lockless Examples and Code Snippets
Community Discussions
Trending Discussions on lockless
QUESTION
This is my implementation of a lockless, waitless, multithread-safe MPMC queue using only atomics:
...ANSWER
Answered 2021-Apr-26 at 06:08If the other bugs are fixed, most likely start
, end
, and precount
can all be memory_order_relaxed in all uses.
postcount
is the variable that signifies that a value has been written to the queue. ie it controls the publishing of the value, and the reading of the value.
So postcount
needs memory_order_release ("publish") in push, and memory_order_acquire before reading (ie in pop).
Maybe.
QUESTION
I wish to create a lockless queue using std::atomic
.
Here's my probably not so good first attempt at trying to do so:
ANSWER
Answered 2020-Sep-26 at 15:38There are several issues with your implementation, some of which you have already identified correctly.
- The race between the two
m_head.store
operations after the CAS onm_tail
- This loop potentially suffers from the ABA problem:
QUESTION
I am making my own channel implementation, but std::task::Context
doesn't make it clear how the waker was generated.
My fake code:
...ANSWER
Answered 2020-Jun-03 at 12:25Yes, it is required to re-set the waker each time. Future::poll
states (emphasis mine):
Note that on multiple calls to
poll
, only theWaker
from theContext
passed to the most recent call should be scheduled to receive a wakeup.
See also:
QUESTION
In my C++ game engine, I have a job system which utilizes worker threads to do various tasks. Threads are affinitized to each available core. Recently, I have been trying to optimize some of my system pipelines by maximizing CPU utilization. Here is some example pseudo-ish code. It isn't an exact replica but the situation is similar.
...ANSWER
Answered 2020-Apr-20 at 07:45@walnut already explained in detail that "accessing different elements of an array is guaranteed to not cause data races".
However, you mentioned that you have multiple job functions updating the entityState, and that these functions are ordered by some jobchain object. You did not go into detail about how this jobchain is implemented, but you have to ensure that it establishes a proper happens-before relation between the different job functions, otherwise you do have a data race on the entiyState members.
And I also agree with @rustyx - run your code with ThreadSanitizer. It helps unveil a lot of threading issues, including data races.
QUESTION
I am creating a very fast multi-threaded discrete event simulation framework. The core of the framework uses atomics and lockless programming techniques to achieve very fast execution across many threads. This requires me to align some variables to cache lines and pad the remaining cache line space so that I don't have cache line contention. Here is how I do it:
...ANSWER
Answered 2017-May-19 at 18:44Taking a page from std::aligned_storage<>
, I've come up with the following:
QUESTION
I am trying to implement a thread-safe lockless container, analogous to std::vector, according to this https://software.intel.com/en-us/blogs/2008/07/24/tbbconcurrent_vector-secrets-of-memory-organization
From what I understood, to prevent re-allocations and invalidating all iterators on all threads, instead of a single contiguous array, they add new contiguous blocks.
Each block they add is with a size of increasing powers of 2, so they can use log(index) to find the proper segment where an item at [index] is supposed to be.
From what I gather, they have a static array of pointers to segments, so they can quickly access them, however they don't know how many segments the user wants, so they made a small initial one and if the amount of segments exceeds the current count, they allocate a huge one and switch to using that one.
The problem is, adding a new segment can't be done in a lockless thread safe manner or at least I haven't figured out how. I can atomically increment the current size, but only that.
And also switching from the small to the large array of segment pointers involves a big allocation and memory copies, so I can't understand how they are doing it.
They have some code posted online, but all the important functions are without available source code, they are in their Thread Building Blocks DLL. Here is some code that demonstrates the issue:
...ANSWER
Answered 2017-Oct-19 at 13:57I would not try to make the segmentsLarge
and segmentsSmall
a union. Yes this wastes one more pointer. Then the pointer, lets call it just segments
can initially point to segmentsSmall.
On the other hand the other methods can always use the same pointer which makes them simpler.
And switching from small to large can be accomplished by one compare exchange of a pointer.
I am not sure how this could be accomplished safely with a union.
The idea would look something like this (note that I used C++11, which the Intel library predates, so they likely did it with their atomic intrinsics). This probably misses quite a few details which I am sure the Intel people have thought more about, so you will likely have to check this against the implementations of all other methods.
QUESTION
In kfifo.h kfifo_get calls kfifo_is_empty which checks if __kfifo->in == __kfifo_out. Meanwhile kfifo_put does __kfifo->in++ after adding data. Since this is a lockless implementation of circular buffer with 1 reader and writer what prevents the writer from corrupting the data while kfifo_is_empty is reading the value of __kfifo->in?
...ANSWER
Answered 2017-Sep-29 at 08:20There is no problem here.
In short, the reader may see in
not equal to out
only after data has been transferred into the kfifo. This is achived by executing barrier before incrementing in
counter at the writer side.
QUESTION
I have a thread pool that should accept any std::packaged_task and give a future.
...ANSWER
Answered 2017-Sep-05 at 14:22Most the code you posted does not compile.
QUESTION
I am trying to select a class template based on a given enum template parameter (store_type). Now I instantiate a class that uses this, but it seems to always try to instantiate the basic_store for this class.
...ANSWER
Answered 2017-Jul-22 at 09:02You forgot the 3rd template argument in the specialization.
QUESTION
I want to use C++17 parallel capabilities to divide every element of a std::vector
by some constant and store the result in another std::vector
of same length and (!!) order.
E.g.
...ANSWER
Answered 2017-Jul-13 at 01:46something like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lockless
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page