|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-02-13 12:03:09
Pavel Vasiliev wrote:
[...]
> > pthread_refcount_decrement() // with msync for proper mut.obj-cleanup
Basically [in terms of proposed/revised Java MM], it's VOLATILE-RELEASE
when count > 1 'prior to decrement' and VOLATILE-ACQUIRE when the count
drops to 0. I think that one might even try to optimize-away VOLATILE-
RELEASE msync [and interlocked instruction(s)] for the'count == 1'-case;
on some platforms, perhaps.
> > pthread_refcount_decrement_nomsync() // without any msync whatsoever
>
> "nomsync" here stands for "no memory view update even when counter drops
> to 0"?
Yes, it's a variant without [VOLATILE-RELEASE/VOLATILE-ACQUIRE] msync.
> 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).
Yeah... "cleanup" for intrusively counted objects [with refs embedded
within the object] aside for a moment...
>
> 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?" :-)
No, you're right. Well, let me put it this way: < ;-) >
Surely you have missed something! See the "// with msync for..."
comment above. It says "for proper mut.obj-cleanup". "mut." stands
for mutable. Obviously, the fact that _no_msync() variant is used
here indicates that destruct_object() [and the rest too] is meant
to be >>'const'<< qualified method[s] that shall not modify any
>>'mutable'<< members (things like "pthread_refcount_t" counts,
mutexes, if any). And all this was crystal clear, I mean.
Good catch. Thanks.
^^^^^(*) Apropos...
regards,
alexander.
(*) http://groups.google.com/groups?selm=3E4B57AB.8BBF5A32%40web.de
(Subject: Re: exceptions)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk