Boost logo

Boost :

Subject: Re: [boost] atomic_count::operator++ return type
From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2009-04-12 05:52:37

De: boost-bounces_at_[hidden] [boost-bounces_at_[hidden]] En nombre de Peter Dimov [pdimov_at_[hidden]]
Enviado el: domingo, 12 de abril de 2009 0:58
Para: boost_at_[hidden]
Asunto: Re: [boost] atomic_count::operator++ return type

> Thanks. I think I see it now.
> Although... I may be missing something, but why doesn't the simple
> explicit refcounted_handle(const Handle& h_):h(h_)
> {
> TrackingHelper::entry(*this).add_ref();
> }
> static bool check_erase(const refcounted_handle& x)
> {
> return TrackingHelper::entry(x).count() == 0;
> }
> work?

This does not work because of scenarios like the following:

1. Thread A detaches the last reference to x and is preempted
when it's about to enter erase.
2. Thread B retrieves x so that its refcount is now 1. After
some work with x, thread B detaches the reference to x,
whose refcount drops again to zero, enters erase and
eliminates x.
3. Thread A resumes, but erase now attempts to work with
a nonexistent x.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

Boost list run by bdawes at, gregod at, cpdaniel at, john at