Lock-free Progress Guarantees in a circular buffer queue

This queue data structure is not strictly lock-free by what I consider the most reasonable definition. That definition is something like: A structure is lock-free if only if any thread can be indefinitely suspended at any point while still leaving the structure usable by the remaining threads. Of course this implies a suitable definition of … Read more

Portable Compare And Swap (atomic operations) C/C++ library?

OPA (Open Portable Atomics) could be a good fit for your needs. https://trac.mcs.anl.gov/projects/openpa/ It provides a consistent C API to common atomic operations across multiple platforms under an MIT-style license. The library is small and certainly meets your size requirements. The current platform list is: GCC inline assembly for x86, x86_64, ia64, PPC 440, and … Read more

Can you avoid locking by guaranteeing that multiple threads won’t access the same memory?

In a conforming C++11 compiler this is safe [intro.memory] (ยง1.7): A memory location is either an object of scalar type or a maximal sequence of adjacent bit-fields all having non-zero width. […] Two threads of execution (1.10) can update and access separate memory locations without interfering with each other. C11 gives identical guarantees (they even … Read more

Using Boost.Lockfree queue is slower than using mutexes

Lock free algorithms generally perform more poorly than lock-based algorithms. That’s a key reason they’re not used nearly as frequently. The problem with lock free algorithms is that they maximize contention by allowing contending threads to continue to contend. Locks avoid contention by de-scheduling contending threads. Lock free algorithms, to a first approximation, should only … Read more

Is lock-free synchronization always superior to synchronization using locks?

Does this imply that, ‘there is no case where using a non-lock-free atomic type would be a better choice over using a lock-free atomic type when the latter is available’ ? (Mainly in terms of performance rather than ease-of-use). No. And that is, in general, not true. Suppose you have two cores and three threads … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)