1. Revision History
1.1. P1372R0
-
Initial version
2. Motivation
[P1298R0], presented at the 2018-11 San Diego meeting, revealed by way of motivation a number of difficulties surrounding the implementation of
. Though the author withdrew the paper, its presence has served as a catalyst for further discussion. The basic issue surrounded the implementation of
for types that cannot be supported in a lock-free manner on certain platforms. In the absence of transactional memory, the current proposal essentially mandates that
for these types must use an address-based, sharded lock table. For many implementations dealing with issues on the fringe of standard C++ (such as dynamic loading of shared libraries and heterogeneity), implementors have expressed the concern that this approach is impractical or impossible. While this paper does not provide a fix for this in the absolutely most general case, it provides a portable means for users to opt in to an alternative implementation that could be significantly more efficient or practical in those cases.
3. Design
We propose a pair of customization point objects, named
and
, that can customized for types
where
both valid and false
. The customization point object mechanism used here is exactly analogous to those for ranges (and thus needs no further discussion here). There are a couple of design questions here, though:
-
Should this customization point be used only when
isatomic_ref < T >:: is_always_lock_free false
, or should the customization also be used in thetrue
case?-
Argument in favor: if the user has a reason (e.g., debugging) for customizing the case where lock-free atomics are available, perhaps the implementation should honor this desire.
-
Argument against: in portable code, the user may wish to provide the customizations because some target implementations will support lock-free atomics on the given type and some will not.
-
Decision: given that one of the design goals
in the first place is portable use of atomic semantics across lock-free and non-lock-free implementations, the design of the customization point should mirror this design intent and allow customization ofatomic_ref < T >
to be ignored when a lock-free implementation is available.T
-
-
Should the implementation be required to use the customization point when
isatomic_ref < T >:: is_always_lock_free false
?-
Argument in favor: Consistency, simplicity, predictable behavior.
-
Argument against: Some implementations may have access to strategies that, while not technically lock-free, may be significantly more efficient than a user can provide in an implementation-independent context (such as OS-emulated transactional memory).
-
Decision: Make it optional for now, but change paper to reflect results of straw poll along these lines.
-
-
Should freestanding implementations be allowed to omit
for types that do not provide a customization of this property?atomic_ref < T > -
Argument in favor: In general, creation of an efficient sharded lock table may be impractical or impossible in freestanding implementations, particularly when those implementations need to inter-operate with a variety of full implementations.
-
Decision: Address this in a follow-up paper to limit the scope of the current paper.
-
-
Should the memory order argument be propagated to the customization points?
-
Argument against: It is unclear how any implementation of
orlock_reference
would use this information, and it can always be added later.unlock_reference -
Decision: No.
-
4. Wording
Make the following changes to [atomics.ref.generic]/3:
The lifetime ([basic.life]) of an object referenced by
shall exceed the lifetime of all
* ptr that reference the object. While any
atomic_refs instances exist that reference the *ptr object, all accesses to that object shall exclusively occur through those
atomic_ref instances or through objects derived from the parameters to customization point objects
atomic_ref and
lock_reference in [atomics.ref.customization] during the execution of the customization . No subobject of the object referenced by
unlock_reference shall be concurrently referenced by any other
atomic_ref object.
atomic_ref
Make the following changes to the note in [atomics.ref.generic]/4:
[Note: Atomic operations or the
constructor could acquire a shared resource, such as a lock associated with the referenced object, to enable atomic operations to be applied to the referenced object. This may (but not must) take the form of a pair of calls to the
atomic_ref and
lock_reference customization points on
unlock_reference where
T is
atomic_ref < T >:: is_always_lock_free false
. —end note]
Add the following paragraph after [atomics.ref.operations]/3:
[Note: The value of
may depend on the presence or absense of the
and
customization points if
is false
. —end note]
Add the following section to the end of [atomics.ref.generic]:
29.6.� Customization points
The following customization points affect the behavior of
for any
such that
is false
. An implementation must not instantiate these customization points for any
such that
is true
.
Signature | Semantics |
|
Customization: Dispatches to Semantics: Obtains exclusive access to |
|
Customization: Dispatches to Semantics: Relinquishes exclusive access to |