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
1
vote
2 answers

Almost lockless producer consumer

I have producer consumer problem to solve with slight modification - there are many parallel producers but only one consumer in one parallel thread. When producer has no place in buffer then it simply ignore element (without waiting on consumer). I…
rnd
  • 123
  • 7
1
vote
1 answer

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 mechanisms. Basically the code looks like this…
Adassko
  • 5,201
  • 20
  • 37
1
vote
1 answer

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 threads may call thread_func(), and I want to…
Itay Bianco
  • 697
  • 6
  • 16
1
vote
1 answer

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 these two variable. I want to change a and b at…
1
vote
0 answers

__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 oldval type newval, ...) These builtins perform an…
BadZen
  • 4,083
  • 2
  • 25
  • 48
1
vote
1 answer

Lockless circular queue with pthreads. Anything to watch out for?

I'd like to implement a lockless single-producer, single-consumer circular queue between two pthreads; in C, on ARM Linux. The queue will hold bytes, the producer will memcpy() things in, and the consumer will write() them out to file. Is it naive…
blueshift
  • 6,742
  • 2
  • 39
  • 63
1
vote
1 answer

Writing to and reading from a hashtable simultaneously

It seems like I should be able to implement a vector-type object that I can insert into and read from simultaneously like so: If there is space in the vector I can just insert things; this shouldn't interfere with reading. If I have to reallocate,…
Daniel McLaury
  • 4,047
  • 1
  • 15
  • 37
1
vote
1 answer

Lock Free stack implementation idea - currently broken

I came up with an idea I am trying to implement for a lock free stack that does not rely on reference counting to resolve the ABA problem, and also handles memory reclamation properly. It is similar in concept to RCU, and relies on two features:…
valenumr
  • 85
  • 5
1
vote
1 answer

Lockfree linked list

I am implementing a lockfree linked list in C, similar to what's available in linux kernel llist.h. I am using atomic operation of "__sync_bool_compare_and_swap". Here is the code snipet: struct llist_head { struct llist_node *head; …
chris.sun
  • 11
  • 3
1
vote
1 answer

What is the value of the "Exclusives Reservation Granule" on STM32F4?

I'm interested since this value affects how data structures where I want to use the (awesome) ldrex/strex synchronization primitives are located in memory. The ARMv7-M Architecture Reference says: The size of the tagged memory block is called the…
unwind
  • 391,730
  • 64
  • 469
  • 606
1
vote
0 answers

Lockless game engine with complete seperation of update and render

I apologize up front for this long post, but as you can probably see I have been thinking about this for quite some time, and I feel I need some input from other people before my head explodes :-) I have been experimenting for some time now with…
uhre
  • 116
  • 2
1
vote
0 answers

Lockless memory buffer protection

While using a lockless queue implementation to store the pointers to a set of buffers that are preallocated, I found that some buffers are still being written by one thread while the other thread starts using it. I have already protected the buffer…
1
vote
0 answers

Producer-Consumer With a Twist

So, I'm trying to solve what essentially is a producer-consumer problem, but slightly different. "Producer" thread creates tokens and adds them to a list "Consumer" thread scans the list of tokens and processes them. As a result of the processing…
nicebyte
  • 1,498
  • 11
  • 21
1
vote
2 answers

Lock Less Key Value data structure

I need a data structure to store 500k keys, each one with some associated data. 150 Threads will be running concurrently & accessing the keys. Once in a day I need to update the data structure since there may be some manipulation operation, say the…
1
vote
1 answer

How does CPMXCG(compare-and-swap) exactly works on a multiprocessor machines?

Imagine a scenario: 2 cores what to do CaS at the same exact same time. A processor needs to read an old value, THEN place a new one, IN the old one is the same. What if they read simultaneously? Or is there any sort of lock put on the variable…
Ilya Smagin
  • 5,992
  • 11
  • 40
  • 57