|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-02-10 11:44:34
Pavel Vasiliev wrote:
> May be the following code answers the challenge? :-).
Interesting...
[...]
> void weak_ref_control_block::release_strong()
> {
> if(atomic_decrement(&strong_count) == 0)
> strong_refs_lost();
> }
> bool weak_ref_control_block::acquire_strong_from_weak()
> {
> scope_lock lock(mutex_destruct);
> if(atomic_increment(&strong_count) > 0)
> return true;
>
> atomic_set(&strong_count, atomic_int_type_MIN);
> return false;
> }
Thread A, in release: atomic_decrement(&strong_count) == 0
Thread B, in acquire: atomic_increment(&strong_count) > 0, return true
Thread A: strong_refs_lost(); // oops, B hates us at this point
Isn't this a problem? Not that I want to break it... I'd like a lock-less
implementation, too. :-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk