4 ms·
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 i
by hellofunk 10y ago
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.
- flamedoge 10y agoIt offers finer grain control than simple mutexes. One can write lock-free data structure easily with it.
- hellofunk 10y agoThe 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-programming/ 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"