Re:Thread Safety Analysis in Clang
by flamedoge on Wednesday March 29, 2017 @04:32AM
(#13984370)
there's also std atomic.
[ Parent
| on HN ]
That does not solve the issue of locks, just abstracts the mechanisms away (hence why std::atomic has member functions related to checking for locks).
The OP is correct, these tools are generally frowned upon in favor of better strategies.
It offers finer grain control than simple mutexes. One can write lock-free data structure easily with it.
The very fact that atomics do lock means that you cannot properly write lock-free data structures with them.
"Lock free" typically refers to code that can prevent blocking operations; atomics do not do that, though some people think of atomics as a simple lock-free method, it really isn't. Lock-free is about algorithm design that can prevent locking in the first place, and atomics still lock, even if they hide that from you. If you mentioned atomics as a lock-free tool in an interview, you'd likely be chided.
Here is more information:
http://preshing.com/20120612/an-introduction-to-lock-free-pr...
"when you attempt to satisfy the non-blocking condition of lock-free programming, a whole family of techniques fall out: atomic operations"
lol... do you have a solution then without using any atomic operations to write a lock-free data structure? Please. give me an example that works.