Is it possible that storage with memory_order_relaxed will never reach other threads?

Suppose I have a stream A , which is written to atomic_int x = 0;using x.store(1, std::memory_order_relaxed);. Without any other synchronization methods, how long will it take before other threads can see this using x.load(std::memory_order_relaxed);? Is it possible that the value written to xremains completely locally-stream given the current definition of the C / C ++ memory model that the standard gives?

The practical case that I have is where thread B often reads atomic_boolto check if it needs to be done; Another thread, at some point, writes true for that bool, and then calls join () on stream B. It’s clear that I don’t mind calling join () before thread B can even see that atom_bool has been installed, and I don't mind when thread B already saw the change and completed execution before I called join (). But I wonder: using memory_order_relaxedon both sides, is it possible to call join () and block forever, because this change never spreads to thread B?

Edit

I contacted Mark Batty (the brain that performs the math test and subsequently captures the requirements for the C ++ memory model). Initially, about something else (which turned out to be a well-known mistake in cppmem and its theses, so, fortunately, I did not make a complete fool of myself and took the opportunity to ask him about this too, his answer was:

Q: , [memory_order_relaxed ( ) ] ?
: , , , .
Q: , ( ), , , ?
Mark: release , .

+4
2

, 29.3.12:

.

, store , .

, store, , , load.
--, .

+1

, , :

[intro.multithread]/28 , ( ), , .

+2

Source: https://habr.com/ru/post/1676208/


All Articles