Questions tagged [seqlock]
9 questions
25
votes
1 answer
Which of these implementations of seqlock are correct?
I am studying the implementation of Seqlock. However all sources I found implement them differently.
Linux Kernel
Linux kernel implements it like this:
static inline unsigned __read_seqcount_begin(const seqcount_t *s)
{
unsigned ret;
repeat:
…

lz96
- 2,816
- 2
- 28
- 46
12
votes
2 answers
GCC reordering up across load with `memory_order_seq_cst`. Is this allowed?
Using a simplified version of a basic seqlock , gcc reorders a nonatomic load up across an atomic load(memory_order_seq_cst) when compiling the code with -O3. This reordering isn't observed when compiling with other optimization levels or when…

Alejandro
- 3,040
- 1
- 21
- 30
6
votes
2 answers
how to implement a seqlock lock using c++11 atomic library
I want to write a seqlock using c++11 atomic library. I have read some questions about seqlock on stackoverflow, but no one helped me. The algorithm I use is common, and you can find it everywhere.That's my code:
struct sequence_spinlock_t {
…

HarryLeong
- 303
- 1
- 8
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
1
vote
1 answer
Can/should non-lock-free atomics be implemented with a SeqLock?
In both MSVC STL and LLVM libc++ implementations std::atomic for non-atomic size is implemented using a spin lock.
libc++ (Github):
_LIBCPP_INLINE_VISIBILITY void __lock() const volatile {
while(1 == __cxx_atomic_exchange(&__a_lock,…

Alex Guteniev
- 12,039
- 2
- 34
- 79
1
vote
1 answer
Atomic and lock-free write of arbitrary sized data/vector/array
I am trying to implement the following functionality:
Atomic and lock-free write or read-modify-write of a data type with arbitrary size (in my case usually a float/int vector with up to 6 elements).
Atomic read from above data type that doesn't…

jffmichi
- 50
- 5
1
vote
1 answer
Why need IRQ-safe version of seqlock for read access?
When write accessing a shared resource protected by a seqlock, a writer must obtain an exclusive lock before entering the critical section. So, as with spinlocks, it makes sense for write accessing with seqlock to have common variants like *_irqsave…

dingcurie
- 121
- 6
0
votes
0 answers
Lock free single real-time writer and one/multiple non-real-time reader
In the paper "Non-blocking synchronization between real-time and non-real-time applications" the following pseudo code is listened in Listing 2. It suggests a non-blocking implementation for a single real-time writer and one or multiple…

Markus Fuchs
- 172
- 9
0
votes
1 answer
Why rwlock is more popular than seqlock in linux kernel?
After reading Robert Love's LKD, I learn rwlock and seqlock, both of them are based on spinlock.
When distinguish between reader and writer, rwlock is better than spinlock, it will get better performace. However, rwlock will make writer…

buwei lv
- 13
- 1