Open AlexGuteniev opened 4 years ago
I would also want to make sure that any use of acq/rel doesn't lead to Independent Reads, Independent Writes problems (which full sequential consistency solves; some algorithms are affected by IRIW).
@giroux said he is working on the memory model implications in a paper for C++23 (if pandemic lets us have a c++23)
Currently
memory_order_acquire
andmemory_order_release
are considered unsafe: The problem is critical sections overlap in the following situation with mutexes or other synch object:Release reorders past subsequent unrelated acquire, so sections overlap and deadlock occurs. The current resolution is believed to be the following:
Unfortunately, 1 is not what Standard currently says, and 2 and 3 has to be confirmed with compiler vendors
Before the status of acquire / release is clarified, currently seq_cst is used in some places, specifically:
atomic_shared_ptr
internal spinlock: https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/inc/memory#L3130 https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/inc/memory#L3150<execution>
(more than just this occurrence): https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/inc/execution#L3624memory_resource.cpp
https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/memory_resource.cpp#L24 https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/memory_resource.cpp#L33 https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/memory_resource.cpp#L43 https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/memory_resource.cpp#L53filesystem.cpp
https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/filesystem.cpp#L36-L50Some places believed to be not affected by the issue still use acquire / release, specifically:
shared_ptr
external spinlock: https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/atomic.cpp#L16-L34<system_error>
https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/inc/system_error#L590-L597atomic_wait.cpp
https://github.com/microsoft/STL/blob/12c684bba78f9b032050526abdebf14f58ca26a3/stl/src/atomic_wait.cpp#L147-L152The task is to confirm the situation with compiler team and decide on using
memory_order_acquire
/memory_order_release
in mentioned and possibly unmentioned preexisting code and new codeNote also that memory model implementation on arm may change in the future, see #83 , see also ##488 , #775 , #1082