86 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
Advice
0
votes
4
replies
147
views
Using lockless atomic operations instead of a mutex
I recently had an interview where I was asked to show how to prevent race conditions in C or C++ between two threads operating on shared data. I used a mutex as follows :
pthread_mutex_t mutex;
int ...
3
votes
1
answer
255
views
Which memory ordering to use in lockless linked-list stack pop() implementation?
I stumbled into an interesting issue -- when it comes to intrusive lockless stacks (single-linked lists) it seems there is a consensus on how push() should look like. All internet/AI searches (and ...
4
votes
1
answer
112
views
Data not ordered properly in lockless spsc queue
I'm trying to write a bounded lockless single-producer, single-consumer queue, however, the order of elements inserted into the queue is not the same as the order of the elements removed from the ...
1
vote
1
answer
733
views
How to implement a ring buffer safely in shared memory safely when the consumer is operating in real-time context
My situation is this: On a Linux machine I have a shared-memory region inside which lives a ring-buffer of audio samples. This ring-buffer's consumer is a hard-real-time Xenomai audio-callback, so ...
1
vote
0
answers
161
views
Confusing "Memory Barrier Example 1" in 《Memory Barriers: a Hardware View for Software Hackers》?
I am reading the great paper 《Memory Barriers: a Hardware View for Software Hackers》 written by Paul E. McKenney, which helps me a lot. But I came across a doubt in 《6.2 Example 1》:
The author has ...
1
vote
1
answer
116
views
Do I need MemoryBarrier to increase index in lockless collection
I'm trying to implement a simple yet fast producer/consumer collection with the ability to be copied from another thread and to make it as fast as possible, therefore I am not using any locking ...
1
vote
1
answer
355
views
Testing lockless buffer copy in C using memory barriers
I have a few questions regarding memory barriers.
Say I have the following C code (it will be run both from C++ and C code, so atomics are not possible) that writes an array into another one. Multiple ...
1
vote
1
answer
87
views
Multithread share 2 variable problem with nonlock
I have a question about multithread share variable problem.
the two variable is like:
{
void* a;
uint64_t b;
}
only one thread can modify the two variable, other thread will frequently read ...
0
votes
1
answer
132
views
free(): invalid next size (fast): when use posix_memalign
I use posix_memalign() to alloc place to put my pointers, but when i try to free this place, it comes to this:
*** Error in `/home/liqiaochu/lockless_rb/test_lockless_rb': free(): invalid next size (...
7
votes
2
answers
3k
views
The definition of lock-free
There are three different types of "lock-free" algorithms. The definitions given in Concurrency in Action are:
Obstruction-Free: If all other threads are paused, then any given
thread will ...
1
vote
0
answers
202
views
__sync_bool_compare_and_swap always returns zero
Am I misunderstanding the builtin CAS operators in gcc?
From the docs:
bool __sync_bool_compare_and_swap (type *ptr, type oldval type newval, ...)
type __sync_val_compare_and_swap (type *ptr, type ...
5
votes
1
answer
704
views
Is using std::atomic_thread_fence right before an atomic load/store with the same order always redundant?
Given:
std::atomic<uint64_t> b;
void f()
{
std::atomic_thread_fence(std::memory_order::memory_order_acquire);
uint64_t a = b.load(std::memory_order::memory_order_acquire);
// code ...
5
votes
1
answer
574
views
Does memory_order_relaxed respect data dependencies within the same thread?
Given:
std::atomic<uint64_t> x;
uint64_t f()
{
x.store(20, std::memory_order::memory_order_relaxed);
x.store(10, std::memory_order::memory_order_relaxed);
return x.load(std::...
3
votes
1
answer
263
views
Lockless deque with non atomic sized items
I'm using a worker deque as described in "Correct and Efficient Work-Stealing for Weak Memory Models". I want queue items to be 16 bytes in size, and I only care about Intel/AMD Windows x64 ...
iam's user avatar
- 1,753
-1
votes
1
answer
188
views
Lockless multithreading of an integer
Given a scenario where there's a function that should only be executed by one thread at any given time, and the rest just return (since a specific state is already being worked on), what's the best ...