According to an article in Jeff Preshing's blog:
A release fence prevents the memory reordering of any read or write which precedes it in program order with any write which follows it in program order.
He also has a great post explaining the differences between release fences and release operations here.
Despite the clear explanations in these blog posts, I'm still confused about how to interpret a release fence call such as
std::atomic_thread_fence(std:memory_order_release);
in terms of memory operation reordering vs the potential fencing mechanisms which provide the guarantees of a release fence.
Is it that compiler must guarantee to circumvent the possibility of a later write call in the thread preceding the fence statement call when compiling to machine code and the CPU must guarantee the same when processing it?
In other words, when exactly does the fence call go from being a statement to being a guarantee?
And most importantly, is there any chance that either compiler or CPU reordering could reorder write operations which succeed the program order of the fence statement, to precede the fence at execution time during that process?