Safe Lock-free Primitives with iceoryx2's ByteAtomic
1–10 of 31 posts
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#2One of the key operations in these algorithms is a memory copy using core::ptr::copy. However, this results in undefined behavior if one process reads the data while another process writes to it concurrently. Even if our lock-free algorithm reliably detects such a race, iceoryx2 cannot depend on undefined behavior in a safety-critical system. This blog post introduces our solution: a byte-wise atomic wrapper that enables well-defined concurrent copy operations. It also shows how it can be used to implement a simple sequence lock.
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#3A sequence lock is a blocking lock. If the writer dies between the two increment operations, then the readers will spin forever waiting for the counter to become even again.
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#4iceoryx2 provides zero-copy inter-process communication mechanisms based on shared memory and data structures that are modified concurrently by multiple processes. One of the key operations in these algorithms is a memory copy using core::ptr::copy. However, this results in undefined behavior if one process reads the data while another process writes to it concurrently. Even if our lock-free algorithm reliably detect…
I'm also missing any acquire/release barrier annotations in your code snippets. If you're using sequentially consistent accesses you might as well just single thread your code, performance wise.
Lastly, in almost all cases it's way more efficient and appropriate to shuffle things on the whole-object level, posting and retrieving pointers, and not poke around inside objects (especially on the byte level). Check how rare the use of seqlocks in the Linux kernel is, compared to other RCU primitives. (and regarding "appropriate", cf. top-level comment by danbruc https://news.ycombinator.com/item?id=49168283 )
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#5A common approach to mitigating the described data race without using blocking locks is to utilize a sequence lock. A sequence lock is a blocking lock. If the writer dies between the two increment operations, then the readers will spin forever waiting for the counter to become even again.
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#6Why is this a problem? Isn't the correct way to deal with a sequence lock failure to just retry? A torn read yes means you get undefined behavior as far as the result of your read, but you throw it all away and start again anyway so what is this solving?
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#7A common approach to mitigating the described data race without using blocking locks is to utilize a sequence lock. A sequence lock is a blocking lock. If the writer dies between the two increment operations, then the readers will spin forever waiting for the counter to become even again.
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#8From the article: >>>The Problem: Even if the reader detects that the data was modified and discards the copy before use, the act of copying the non-atomic data itself still triggers undefined behavior. While a sequence lock can detect that a data race occurred, it does not prevent it. Why is this a problem? Isn't the correct way to deal with a sequence lock failure to just retry? A torn read yes means you get undefi…
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#9A common approach to mitigating the described data race without using blocking locks is to utilize a sequence lock. A sequence lock is a blocking lock. If the writer dies between the two increment operations, then the readers will spin forever waiting for the counter to become even again.
Also, there's no guarantee of progress. The writer can starve the reader forever.
All the claims about something being lock-free and/or wait-free depend on a rational behavior of the writers.
If any writer acts crazy, progress becomes impossible regardless of what all others do, unless someone kills the rogue thread or process.
In practice, the algorithm from TFA is much more likely to guarantee progress than any of the algorithms that are theoretically proven to guarantee progress, because it has an extremely small overhead, while the alternatives are much more complex and they waste a lot of time.
Moreover, most wait-free algorithms guarantee progress only for the whole system, in the sense that one random thread will progress, but they do not guarantee anything for a given thread, which may be blocked forever or stuck in an infinite loop, if unlucky.
Re: Safe Lock-free Primitives with iceoryx2's ByteAtomic
#10A common approach to mitigating the described data race without using blocking locks is to utilize a sequence lock. A sequence lock is a blocking lock. If the writer dies between the two increment operations, then the readers will spin forever waiting for the counter to become even again.
This is why wait-free and lock-free are separate concepts. Author is not claiming wait-free.