
________________________________________ De: boost-bounces@lists.boost.org [boost-bounces@lists.boost.org] En nombre de Peter Dimov [pdimov@pdimov.com] Enviado el: domingo, 12 de abril de 2009 0:58 Para: boost@lists.boost.org 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