Questions tagged [lockless]

Lockless operations guarantee simultaneous access to data structures without the usage of conventional locks which are generally slow operations like critical sections, mutexes etc. Lockless operations can be achieved with atomic operations for example.

Lockless operations guarantee simultaneous access to data structures without the usage of conventional locks which are generally slow operations like critical sections, mutexes etc. Lockless operations can be achieved with atomic operations() for example.

82 questions
3
votes
1 answer

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 and VS 2019. I understand that 16 byte (Say __m128)…
iam
  • 1,623
  • 1
  • 14
  • 28
3
votes
1 answer

How does "lock cmpxchg" work in assembly?

I came across this old (GCC prior to 4.8.3 -- bug 60272) bug report https://gcc.gnu.org/ml/gcc-bugs/2014-02/msg01951.html . This is fixed now. But I have a question regarding this. I compiled the following code snippet #include struct Node…
Writo
  • 33
  • 4
3
votes
1 answer

SpinWait in lockless update

While reading Albahari's Threading in C#, I've noticed that the "lock free update" pattern uses a SpinWait at the end of the cycle: static void LockFreeUpdate (ref T field, Func updateFunction) where T : class { var spinWait = new…
Lou
  • 4,244
  • 3
  • 33
  • 72
3
votes
1 answer

Deleted node detection in lockless fifo buffer

I've been working on a lockless c++11 fifo buffer. And I've almost got it. However one small detail has gotten the better of me. The buffer has a head pointed to by: std::shared_ptr> m_head; Of the type: struct node { …
laurisvr
  • 2,724
  • 6
  • 25
  • 44
2
votes
3 answers

Implementing a lock-free queue (for a Logger component)

I am designing a new improved Logger component (.NET 3.5, C#). I would like to use a lock-free implementation. Logging events will be sent from (potentially) multiple threads, although only a single thread will do the actual output to file/other…
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
2
votes
0 answers

Why doesn't C++11 standard provide other lock free atomic structure

I've known that std::atomic_flag is guaranteed to be lock free whereas other atomic stuffs, such as std::atomic, std::atomic are not, meaning that they may be generated with lock. My question is why there is only one thing…
Yves
  • 11,597
  • 17
  • 83
  • 180
2
votes
1 answer

Is boost::lockfree::queue (in multithreaded program) lockable?

I am working on a program where, 2+ (gstreamer) boost:: threads and same number of boost:: threads of a dummy application are simultaneously using a queue. Now this queue is used for synchronization between tasks of gstreamer thread with its…
RC0993
  • 898
  • 1
  • 13
  • 44
2
votes
1 answer

Implementing 64 bit atomic counter with 32 bit atomics

I would like to cobble together a uint64 atomic counter from atomic uint32s. The counter has a single writer and multiple readers. The writer is a signal handler so it must not block. My idea is to use a generation count with the low bit as a read…
ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
2
votes
0 answers

why atomic primitive helps accelerating performance even the multiple user actually still need wait another

There is a kind of lockless ring buffer which uses the compare and swap atomic operation to work around lock. It was saying that this lockless ring buffer improves the performance. But checking the implementation of the lockless algorithm, you will…
riveridea
  • 53
  • 5
2
votes
1 answer

Given sufficient memory, are locks unnecessary when there is only a single dedicated writer thread?

For a scenario with multiple reader threads and a single writer thread, where the readers are allowed to read slightly outdated data, I've concocted a lockless control flow as shown below in its most basic form in pseudocode: GLOBAL_ATOMIC_POINTER…
Will
  • 2,014
  • 2
  • 19
  • 42
2
votes
2 answers

Lockless reader/writer

I have some data that is both read and updated by multiple threads. Both reads and writes must be atomic. I was thinking of doing it like this: // Values must be read and updated atomically struct SValues { double a; double b; double c; …
Rabbit
  • 1,741
  • 2
  • 18
  • 27
2
votes
2 answers

lock-free bounded MPMC ringbuffer failure

I've been banging my head against (my attempt) at a lock-free multiple producer multiple consumer ring buffer. The basis of the idea is to use the innate overflow of unsigned char and unsigned short types, fix the element buffer to either of those…
sheredom
  • 65
  • 3
2
votes
1 answer

Lock free multiple reader, single writer Linked List

I have been exploring various solutions online for lockless/lock free linked lists. I have come across techniques like RCU, hazard pointers, and publications on auxilary nodes / "marking" nodes, etc to solve this problem. They all solve concurrency…
Rand
  • 251
  • 1
  • 2
  • 4
1
vote
1 answer

When using CAS (Compare And Swap), how do I ensure the old value is actually old?

Consider the following: int grab_next_target(int* target) { do { /* Intention: store current value of *target into old, so as to ensure that old never changes */ …
MrAnonymous
  • 717
  • 3
  • 7