Например:
Код: Выделить всё
#include
#include
#include
int main(){
std::atomic state = {0};
int protect_v = 0;
std::thread t1([&](){
int expected = 0;
if(state.compare_exchange_strong(expected,1,std::memory_order::release,std::memory_order::acquire)){
protect_v = 2;
}else{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79183275/can-the-combination-of-pure-load-and-a-store-model-the-rmw-operation[/url]
Мобильная версия