[cpp-threads] Yet another visibility question

Peter Dimov pdimov at mmltd.net
Sat Jan 13 23:16:56 GMT 2007


Herb Sutter wrote:
> Paul wrote:
>> Do we all agree that the only reason for using something like
>> atomic<> is to -increase- performance?
>
> A common reason to use something like atomic<> instead of a lock is
> to avoid the potential for a program to deadlock -- with itself
> (i.e., for basic correctness) or especially with separately authored
> parts (i.e., for composability).

If the operations under the lock are non-blocking, there is no possibility 
of deadlock. Limiting the critical section to reads or updates to a single 
variable is one way to do that, of course. 




More information about the cpp-threads mailing list