A C atomic flag publishes data only through a matching order
An atomic flag can communicate that a write occurred, but ordinary data becomes safely visible to another thread only when the flag operations establish synchronization.
Atomicity and visibility answer different questions
A shared flag often looks like a complete publication mechanism: one thread fills a structure, sets the flag, and another thread waits for it. But “the flag is atomic” and “the structure is visible” are separate claims. Atomicity prevents conflicting accesses to the flag from tearing or forming a data race on that flag. Ordering determines whether operations on other objects are made visible across threads.
In C, two threads that access the same non-atomic object, with at least one access modifying it, need a happens-before relationship. Without one, the conflicting actions form a data race and the program has undefined behavior. Making an adjacent status variable atomic does not retroactively make the payload atomic or order its accesses. [1]
A release store and acquire load form a handoff
For a one-time handoff, suppose a producer initializes a payload and then publishes a flag. It can write the payload first and use atomic_store_explicit(&ready, true, memory_order_release) for the flag. A consumer can poll with atomic_load_explicit(&ready, memory_order_acquire) and read the payload only after observing the published value. The release operation synchronizes with an acquire operation that reads the value written by that release (or a value in its release sequence). The payload write is sequenced before the release; the payload read is sequenced after the acquire. Together those edges establish happens-before for the ordinary payload access. [1]
The exact value read matters. An acquire load does not synchronize merely because it is an acquire load; it must read from the relevant release operation or its release sequence. If the flag was already true from initialization, or another publication overwrote it, the consumer may have observed a different event. The program’s protocol must make the relationship between a particular payload version and a particular flag value unambiguous.
Relaxed operations protect only the atomic object
Changing both flag operations to memory_order_relaxed still gives the flag atomic access and a modification order for that atomic object. It does not create the cross-thread ordering needed to make a concurrent ordinary payload access safe. The reader may observe the flag value without having an ordering guarantee for the producer’s earlier payload stores. If the payload itself is accessed concurrently, the program can still have a data race. [1]
Relaxed ordering is useful when the atomic value is the whole shared fact: for example, a counter whose numerical value is updated and read atomically, with no associated ordinary state that those operations must publish. It can also be part of a larger protocol whose synchronization comes from a different object or mechanism. The choice follows the communication graph, not a general rule that “flags should be relaxed” or that “all atomics should be sequentially consistent.”
Make the protocol assumptions visible
The simple flag pattern assumes one producer initializes the payload before publication, one consumer reads it only after the acquire succeeds, and the payload is not modified concurrently afterward. If the producer reuses the payload, clears and sets the same flag for another round, or has multiple consumers, the design needs additional rules. A Boolean can return to its old value, so a delayed reader may not be able to tell which generation it observed. A generation counter, ownership transfer, mutex, or queue can make reuse and multiplicity explicit.
Likewise, synchronization does not solve lifetime. A pointer published through an atomic pointer still needs a rule ensuring the pointed-to object remains alive while readers use it. Release/acquire establishes ordering for accesses in the relevant happens-before chain; it is not memory reclamation, mutual exclusion, or a proof that the data structure has no other races.
Treat compiler built-ins as a separate interface
C code can express this pattern with <stdatomic.h> and _Atomic objects. GCC also provides __atomic built-ins for code that deliberately depends on the GCC interface. Its manual lists the memory-order arguments and describes them as approximations of the C++11 memory model, noting that precise semantics come from that language model. That is a compiler-specific API choice, not a reason to mix C atomic rules and compiler built-ins casually. [2]
When reviewing a publication flag, trace four things: which write produces the payload, which release operation follows it, which acquire operation reads from that release sequence, and which payload reads occur afterward. Then check what happens on a second publication and who owns the payload lifetime. If any link is missing, a stronger-sounding memory-order name cannot supply the absent protocol.