From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-09-27 14:36:16
John Torjo wrote:
> Ben Hutchings wrote:
>> expired() may read the count as still being 1 and so return false,
>> but I believe the wnd_shared_ptr constructor will catch the fact
>> that the pointer really has expired. Unfortunately I can't yet
>> see the code to confirm this!
> By looking at the code, I would think not. But I may be wrong.
As the comment says, the if( expired() ) test is only an optimization.
Remove it if it makes you feel better. ;-)
The main idea is that a weak_ptr can never transition by itself from an
expired() state back to a !expired() state unless you explicitly assign to
Because you are in weak_ptr::lock at the moment - a read access - you know
that no other threads assign to *this, because this would be a violation of
the "basic thread safety" requirements.
Therefore, if expired() returns true, it will continue returning true for
the foreseeable future, and you can skip the rest of lock().
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk