[cpp-threads] Weak vs Strong Atomics
Boehm, Hans
hans.boehm at hp.com
Thu May 3 23:10:30 BST 2007
> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf
> Of Roger Orr
> Sent: Thursday, May 03, 2007 12:01 PM
> To: 'C++ threads standardisation'; c++std-ext at accu.org
> Subject: RE: [cpp-threads] Weak vs Strong Atomics
>
>
> > First, I don't think the notion that you can pass a weak
> atomic to a
> > module expecting a strong atomic actually works.
> > The passee may be expecting SC semantics, but the passer
> may still be
> > using it weakly, thus failing SC. Conversely, as noted, passing a
> > strong atomic to a weak atomic also may yield non-SC
> behavior to the
> > passer. So, at a minimum, meeting the stated goal of the decision
> > requires complete isolation of the weak atomics from the strong
> > atomics, and that was not my understanding of the decision.
>
> That matches my understanding that we were proposing a class
> hierarchy, where weak_atomic was derived from strong_atomic,
> as we thought a weak atomic IS-A strong atomic.
>
> I think your first sentence shows that assumption is invalid.
>
I can't quite convince myself of this.
Assume I have a weak atomic x in A, and I pass it to B as a strong
atomic. A continues to apply weak operations to it while B uses it.
Does that allow any behavior that wouldn't already be exhibited by the
case in which A runs a few threads repeatedly executing the strong
operation
x = random();
in a tight loop?
It seems to me that whether or not A gets to apply weak operations, it
has to behave such that B sees correct values for x. There are no doubt
more ways to get that wrong with weak operations. But I have a hard
time pinning down any sense in which x fundamentally does not look like
a strong atomic to B.
Having said that, I don't have a strong opinion on this issue. I think
either approach works for the usage models I expect to see:
- Only strong atomics
- Only weak atomics
- Coding initially with strong atomics and making isolated use of weak
atomics for tuning
But I would prefer not to reopen this discussion if it does turn out to
be controversial.
Hans
More information about the cpp-threads
mailing list