|
Boost : |
From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-09-28 07:12:48
John Torjo <john.lists_at_[hidden]> wrote:
> Ben Hutchings wrote:
<snip>
> > 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.
> Anyway, I've posted the code in my other post.
Thanks for that. Supposing that expired() wrongly returns false
because use_count is really 0 but it gets an old non-zero value.
Then lock() attempts to construct a shared_ptr:
calls shared_ptr<T>::shared_ptr<T>(weak_ptr<T> const &)
calls detail::shared_count::shared_count(weak_count const &)
calls detail::sp_counted_base::add_ref_lock()
calls detail::atomic_conditional_increment(
long volatile &)
either reads the count as 0
or calls _InterlockedCompareExchange
fails and returns 0
then loops around and reads the count as 0
returns 0
throws bad_weak_ptr
catches bad_weak_ptr
returns 0
OK?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk