0

I heard this is possible, but I cannot think of an example where this makes sense. Please give an example. Also, if a lock - free algorithm is using a lock, how do we prove that it is actually lock free?

jannè
  • 3
  • 3
  • If you mean lock-free in the technical computer-science sense (https://en.wikipedia.org/wiki/Non-blocking_algorithm#Lock-freedom), then using an actual lock is impossible: a thread that sleeps or dies with the lock held will delay others indefinitely. Maybe you could make a silly algorithm for claiming a tmp buffer where you try to take a lock and move on to the next one if it's not available, with more buffers than threads. See also [Lock-free Progress Guarantees](//stackoverflow.com/q/45907210): a lockless algo doesn't have to be lock-free to be useful and scale well in practice. – Peter Cordes Jul 01 '18 at 22:34
  • Or are you talking about using C++11 `std::atomic` with large types such that `foo.is_lock_free()` is false? In that case the algorithm might be lock-free, but the actual implementation will not be on implementations where atomic ops on types that large have to be emulated with locks. See [Where is the lock for a std::atomic?](https://stackoverflow.com/q/50298358) – Peter Cordes Jul 01 '18 at 22:37

0 Answers0