(no title)
Ace17 | 5 years ago
[...]
A final precision: Operations that are designed to block do not disqualify the algorithm. For example, a queue’s pop operation may intentionally block when the queue is empty. The remaining codepaths can still be considered lock-free. ```
I don't get it ; how could "locking a mutex" not be considered as an "operation that are designed to block" ?
Would somebody be kind enough to tell me what am I missing here? Thanks !
jganetsk|5 years ago
That's not what is being claimed here. What is being said is that an algorithm that blocks a thread can still be considered lock-free. There's a difference between lock-freedom and wait-freedom.
zaarn|5 years ago
The queue implementation that blocks on an empty queue is fine if inserting into the queue is still lock-free, ie, your insert operation eventually completes or makes progress regardless of if a reader is spinning on the lock that allows you to pop a value from the queue.
That means, while the popping of a value is locking, inserting is not. Hence the mutex locking the read does not turn the queue into a locking algorithm.
saghm|5 years ago
brianberns|5 years ago
That seems too extreme to me. If the scheduler itself is potentially malicious, then no multi-threaded implementation is safe, since we can't assume that any thread we start will ever actually run.
johnbender|5 years ago
If the properties of concern for your thread or program are only safety properties (“never does a bad thing”) then the fact that the program may never do anything at all is just fine!
Then, if you want some liveness properties (“eventually does something good”) you’ll need to embed some assumption about fairness/scheduling/progress just as you’ve said!
This appears in early concurrency literature (TLA etc which I can’t be bothered to look for)
manicdee|5 years ago
Remembering that you are your own worst enemy, what this implies is that some other perfectly sane decision you made in the past has come to bite you in the arse.
thmt|5 years ago
As omazurov mentioned as a top-level comment, threads can also die, which is rather like never being scheduled. In practice, I suspect that you're right that it's often too extreme of a model—many programs use locks and don't worry too much about this issue.
colanderman|5 years ago
nyanpasu64|5 years ago
insulanus|5 years ago
Or, another way to look at it - a lock-free algorithm that allows starvation or livelock/deadlock.
jganetsk|5 years ago
read_if_gay_|5 years ago