Fw: [patch] Make std::tr1::shared_ptr thread-safe.

Alexander Terekhov alexander.terekhov@gmail.com
Thu Mar 31 15:46:00 GMT 2005


Just to clarify. Peter Dimov wrote:

: Apologies for repeating myself, but this is an important point: the empty 
: critical sections fix a different problem (memory visibility). The 
: compare_and_swap way is not a substitute for them. It eliminates the 
: non-empty critical section in add_ref_lock, nothing more. 

Right. As for memory visibility, the issue here is that shared_ptr's 
"control block" is mutable object. The msync protocol on "self count" 
must take care of inter-thread ordering with respect to modifications 
(of another "use count", I mean) and destruction of control block. 
If it doesn't, then empty critical sections at the right places (on 
the same lock) can be used to sorta compensate that.

regards,
alexander.



More information about the Libstdc++ mailing list