, release/ . x86
, , @Adam Rosenfield Wikipedia. x86 .
Kerrek SB :
, , x86 , , /. ( mfence.)
, ! (. cppreference).
, ...
#include <atomic>
#include <cassert>
#include <string>
std::atomic<std::string*> ptr;
void producer()
{
std::string* p = new std::string("Hello");
ptr = p;
}
void consumer()
{
std::string* p2;
while (!(p2 = ptr))
;
assert(*p2 == "Hello");
}
(g++ -std = ++ 11 -S -O3 x86)
... mfence x86 (
).
...
#include <atomic>
#include <cassert>
#include <string>
std::atomic<std::string*> ptr;
void producer()
{
std::string* p = new std::string("Hello");
ptr.store(p, std::memory_order_release);
}
void consumer()
{
std::string* p2;
while (!(p2 = ptr.load(std::memory_order_acquire)))
;
assert(*p2 == "Hello");
}
(g++ -std = ++ 11 -S -O3 x86)
... no mfence , x86 .