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
18
votes
5 answers

How do I build a lockless queue?

I've spent today looking into lockless queues. I have a multiple producer, multiple consumer situation. I implemented, for testing, a system using the Interlocked SList thing under Win32 and it doubled the performance of my heavily threaded task…
Goz
  • 61,365
  • 24
  • 124
  • 204
14
votes
1 answer

If I don't use fences, how long could it take a core to see another core's writes?

I have been trying to Google my question but I honestly don't know how to succinctly state the question. Suppose I have two threads in a multi-core Intel system. These threads are running on the same NUMA node. Suppose thread 1 writes to X once,…
Cube Fan
  • 143
  • 4
13
votes
1 answer

Implementing concurrent_vector according to intel blog

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…
ulak blade
  • 2,515
  • 5
  • 37
  • 81
12
votes
2 answers

What's the difference between lockless and lockfree?

In some articles about algorithm, some use the word lockfree, and some use lockless. What's the difference between lockless and lockfree?…
superK
  • 3,932
  • 6
  • 30
  • 54
10
votes
6 answers

Is there such a thing as a lockless queue for multiple read or write threads?

I was thinking, is it possible to have a lockless queue when more than one thread is reading or writing? I've seen an implementation with a lockless queue that worked with one read and one write thread but never more than one for either. Is it…
user34537
10
votes
2 answers

Is Clojure lockfree by using lockfree algorithms?

I'm progressing in my Clojure quest (about 80 problems solved on 4clojure.com) and I keep on reading and coding and trying to "get it". Now I'm a bit confused by Clojure being designed for "lockless concurrency". I know all too well about deadlocks…
Cedric Martin
  • 5,945
  • 4
  • 34
  • 66
8
votes
1 answer

Do any array based, bounded, wait free stacks exist?

I have a problem that requires me to use a highly concurrent, wait free implementation of a stack. I have to preallocate all memory (no garbage collection or mallocs) in advance and it is acceptable that the stack is bounded in size (push may return…
Thomas Kejser
  • 1,264
  • 1
  • 10
  • 30
8
votes
2 answers

How to implement zero-copy tcp using lock-free circular buffer in C++

I have multiple threads that need to consume data from a TCP stream. I wish to use a circular buffer/queue in shared memory to read from the TCP socket. The TCP receive will write directly to the circular queue. The consumers will read from the…
jaybny
  • 1,026
  • 2
  • 13
  • 29
7
votes
2 answers

what is the different of busy loop with Sleep(0) and pause instruction?

I would like to wait on an event in my app which supposed to happen immediately, so I don't want to put my thread on wait and wake it up later. I wonder what are the difference between using Sleep(0) and hardware pause instruction. I cannot see any…
sramij
  • 4,775
  • 5
  • 33
  • 55
7
votes
4 answers

Is there an atomic |= operation?

Is there such a thing as an atomic |= or and atomic or? If no what is the recommended technique for setting a bit in an variable that needs to be threadsafe? (I am avoiding locks)
user34537
7
votes
0 answers

Why can _mm_pause() significantly improve performance?

According to Intel's manual (on page 112): void _mm_pause(void) The execution of the next instruction is delayed an implementation specific amount of time. The instruction does not modify the architectural state. This intrinsic provides…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
7
votes
1 answer

How can I implement ABA counter with c++11 CAS?

I am implementing a lock-free queue based on this algorithm, which uses a counter to solve the ABA problem. But I don't know how to implement this counter with c++11 CAS. For example, from the algorithm: E9: if CAS(&tail.ptr->next, next,
BugRepairMan
  • 221
  • 2
  • 9
7
votes
2 answers

Is Go's buffered channel lockless?

Go's buffered channel is essentially a thread-safe FIFO queue. (See Is it possible to use Go's buffered channel as a thread-safe queue?) I am wondering how it's implemented. Is it lock-free like described in Is there such a thing as a lockless queue…
Song Gao
  • 2,008
  • 15
  • 18
6
votes
2 answers

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 complete its operation in a bounded number of…
6
votes
4 answers

A readers/writer lock... without having a lock for the readers?

I get the feeling this may be a very general and common situation for which a well-known no-lock solution exists. In a nutshell, I'm hoping there's approach like a readers/writer lock, but that doesn't require the readers to acquire a lock and thus…
Swiss Frank
  • 1,985
  • 15
  • 33
1
2 3 4 5 6