Alexander Terekhov wrote: [...] > Pavel Vasiliev wrote: >> I place here the corrected version of my previous code.
> Well, > Given: two threads -- A and B, > thread A has "strong" one, > thread B has "weak" one, > strong_count == 1, weak_count == 2. > Thread A, in release_strong: > atomic_decrement(&strong_count) == 0, > Thread B, in acquire_strong_from_weak: > lock, > see atomic_increment(&strong_count) > 0, > (strong_count == 1, weak_count == 2) > return true (and unlock), > ... > enter release_strong() > atomic_decrement(&strong_count) == 0, > enter strong_refs_lost(), > see strong_count == 0, > set strong_count < 0, > unlock, > destroy, > enter release_weak(), > atomic_decrement(&weak_count) == 1, > (strong_count < 0, weak_count == 1) > ... > enter release_weak(), > atomic_decrement(&weak_count) == 0, > destruct_self() > Thread A, enter strong_refs_lost(): Yeah... This attempt failed :-(. Thanks for preventing me from getting into troubles! However, > WHA.. Nah, Lukashenko retires and establishes peace and democracy in > the Middle East. ``Not bad.'' ;-) I'd better leave my code as is. Or even dereference a NULL-pointer :-). [...] > pthread_refcount_decrement() // with msync for proper mut.obj-cleanup > pthread_refcount_decrement_nomsync() // without any msync whatsoever "nomsync" here stands for "no memory view update even when counter drops to 0"? If yes, then you probably should not use it in > void release_weak() { > int status = pthread_refcount_decrement_no_msync(&weak_count); > if (PTHREAD_REFCOUNT_DROPPED_TO_ZERO == status) > destruct_self(); > } Consider the following: > Given: two threads -- A and B, > thread A has "strong" one, > thread B has "weak" one, > strong_count == 1, weak_count == 2. Thread A releases the last "strong" reference. destruct_object() deletes p_object AND modifies the refs instance (e.g. sets p_object to NULL for debug reasons). strong_count == 0, weak_count == 1 Thread B releases the last "weak" reference. release_weak() calls destruct_self() on expired memory view. "Or am I just missing and/or misunderstanding something?" :-) Pavel _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost