3 ms·
Have you ever used one? Please go read all the stuff about java.util.concurrent. It holds for almost all lock-free libraries, but it's way better documented t
by bsder 11y ago
Have you ever used one? Please go read all the stuff about java.util.concurrent. It holds for almost all lock-free libraries, but it's way better documented than anything else.
They provide consistency and atomicity. Lock-free data structures are always in a consistent state. The view they provide is always "atomic". It moves from one consistent state to another with no inconsistent state ever visible in-between.
They provide isolation under composition quite well. They compose far better than locks which can't even handle a simple inversion of order.
What they generally don't provide are guarantees of progress under high contention. The structure will never be wrong, but it may not be efficient.
The problem is that everybody equates "consistent" and "atomic" with "absolutely must exist in one and only one place at all times". And that's too strong for most uses.
Yes, if you are writing bank software, you want that transaction to ever only exist in exactly one place.
But, 99% of the time, that's too strong a guarantee.
- chrisseaton 11y agoYeah I've read the literature and used lock-free data structures extensively. I've got a chapter in my PhD thesis about data-flow concurrency structures which were implemented using lock-free constructs, and I work in Oracle Labs on JVM research. You've suggested a definition of consistency which is something like "could possibly exist in zero or more than one place at the same time". Well that's useless! Anything could be consistent with that definition! So really I think you agree with me that you cannot compose multiple operations on a lock-free data structure and get any degree of atomicity, consistency or isolation. But you just don't think that matters for most programs, so you weaken the definitions until they could be met by anything. > Yes, if you are writing bank software, you want that transaction to ever only exist in exactly one place. Right so this answers your question! > Sigh. What's wrong with using lock-free data structures? Because - as you say! - they don't meet all requirements! Finally - I don't think we even have lock-free implementations of all data structures do we? So it's not even always an option.