Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-09-24 11:32:57


John Torjo wrote:
[...]
> Whenever a thread (other than main) wants to access this window, it will
> query the weak_pointer. The weak_pointer needs to know the LATEST
> reference count in order to know if the weak pointer is still valid.
> Thus, atomic_read that simply returns the value is not enough.

No barriers needed for its lock() call (and shared_ptr-from-weak_ptr
ctor). It can't see 'false' zero unless you violate the "basic" thread-
safety contract. Value consistency is ensured by conditional increment
using 'naked' (w/o any barriers) CAS (LL/LR-SC aside for a moment) IFF
the observed 'old' value is not zero.

Also, < Forward Inline >

-------- Original Message --------
Message-ID: <415446A0.F2BD31CF_at_[hidden]>
Newsgroups: comp.lang.c++.moderated
Subject: Re: Vindicated? Sutter and COW Strings
References: ... <slrncl63k0.pk.ben-public-nospam_at_[hidden]>

Ben Hutchings wrote:
[...]
> The odd thing is that there is no obvious way to read with an acquire
> or any other kind of memory barrier. It is possible to do this using
> InterlockedCompareExchange with the exchange and comparand set to the
> same value, preferably an unlikely one to avoid invalidating cache
> lines. (John Torjo suggested this on the Boost mailing list.) This
> provides a full memory barrier; recent versions of Windows have
> variants of the function that provide a acquire or release barrier.

Take a closer look at MS docu. See also:

http://google.com/groups?threadm=XIRDc.192766%24Ly.83841%40attbi_s01
(Subject: Re: DCSI - thread safe singleton)

I mean followups too.

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk