Title
Atomics Library Issue
Status
cd1
Section
[atomics.types.operations]
Submitter
Lawrence Crowl

Created on 2008-01-21.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Add the const qualifier to *object and *this.

C atomic_load(const volatile A* object);
C atomic_load_explicit(const volatile A* object, memory_order);
C A::load(memory_order order = memory_order_seq_cst) const volatile;
Date: 2010-10-21.18:28:33

[ post Bellevue Peter adds: ]

Issue 777 suggests making atomic_load operate on const objects. There is a subtle point here. Atomic loads do not generally write to the object, except potentially for the memory_order_seq_cst constraint. Depending on the architecture, a dummy write with the same value may be required to be issued by the atomic load to maintain sequential consistency. This, in turn, may make the following code:

const atomic_int x{};

int main()
{
  x.load();
}

dump core under a straightforward implementation that puts const objects in a read-only section.

There are ways to sidestep the problem, but it needs to be considered.

The tradeoff is between making the data member of the atomic types mutable and requiring the user to explicitly mark atomic members as mutable, as is already the case with mutexes.

Date: 2008-01-21.00:00:00

The load functions are defined as

C atomic_load(volatile A* object);
C atomic_load_explicit(volatile A* object, memory_order);
C A::load(memory_order order = memory_order_seq_cst) volatile;

which prevents their use in const contexts.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3740
2010-10-21 18:28:33adminsetmessages: + msg3739
2008-01-21 00:00:00admincreate