on Sat Aug 16 2008, "Eduardo Panisset"
Excuse me for insisting on my question,
But I would like to ensure that I'm understanding shared_ptr correctly.
Okay, but please use standard quoting so threading is preserved:
Not without additional synchronization (e.g. via a mutex with all threads cooperating by locking before accessing the shared_ptr). But do you really need to do that? Can you not give each thread that needs access a separate copy of the shared_ptr?
Exactly. I give each thread a instance of shared_ptr, but the point is: the critical region of release member function does not avoid race conditions because It does not protect de code right below:
if( new_use_count == 0 ) { dispose(); weak_release(); }
How Can I ensure that the release member function wouldn't dispose a pointee more than one time ? (release executing concurrently from different shared_ptr instances)
Because the reference count was 1, there can be only one shared_ptr instance that owns the pointee. No other threads can be referencing it. [In fact it's very likely that no mutex is used on any given platform -- atomic reference counting is used where available.] -- Dave Abrahams BoostPro Computing http://www.boostpro.com