[cpp-threads] Weak vs Strong Atomics

Raul Silvera rauls at ca.ibm.com
Fri May 4 12:29:39 BST 2007


Lawrence Crowl wrote on 05/03/2007 12:50:20 AM:

> At the Oxford meeting there was a decision to have weak versus
> strong atomics so that strong atomics couldn't be reused weakly,
> thus failing to provide sequential consistency.  I think that the
> decision should be reconsidered, or at least modified.
>
> 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.
>
> Second, I don't think atomic variables are likely to be shared among
> disparate code.  The reason is that the use of atomic variables is an
> implementation technique, not an interface issue.  For example, a
> queue could be implemented with either mutexes or with atomics,
> and that decision is an implementation decision.  There might be
> lock-free semantics exported, but the specific atomic variables are
> typically not exported and not part of the interface.  So the notion of
> passing these variables to an uncooperative software module seems
> implausible.
>
> Based on these two observations, I would like to keep the current
> design for atomics, which is a single atomic type and a functional
> interface to all operations and an operator interface to the strong
> operations.
>
> Comments?
>

Hi, Lawrence... First let me introduce the motivation as to why
we want replaceability of strong atomics with weak atomics. We foresee
situations where a program is initially written using strong atomics,
but later as part of a tuning effort weak atomic operations are introduced
selectively on the performance-sensitive sections of the program.

An inheritance relationship will allow the programmer to replace the
declaration of a strong atomic variable with a weak atomic with minimal
source changes and without changing the program semantics (weak atomics
behave as strong atomics by default) and then selectively replace
individual atomic operations with weakly ordered operations.

With respect to your first argument, I don't think that it is in reality
a problem. There will still be SC on the operations performed by the
passee, and the passee cannot be expecting SC on operations performed by
the passer, since it does not have any visibility into that code.

--
Raúl E. Silvera         IBM Toronto Lab   Team Lead, Toronto Portable
Optimizer (TPO)
Tel: 905-413-4188 T/L: 969-4188           Fax: 905-413-4854
D2/KC9/8200/MKM





More information about the cpp-threads mailing list