Reputation: 2077
I need to add two memory fences into my codes, in order to prevent my codes from being reordered by either the compiler or CPU.
Like this:
rec.time_stamp0 = std::system_clock::now();
std::atomic_signal_fence( std::memory_order::release );
/*
do many things...
*/
std::atomic_signal_fence( std::memory_order::acquire );
rec.time_stamp1 = std::system_clock::now();
Here I want to ensure that rec.time_stamp0 = std::system_clock::now();
certainly be executed before all other codes, and that rec.time_stamp1 = std::system_clock::now();
must be after all others.
My questions:
std::system_clock::now()
natively come with a memory fence(it's a
syscall)? So explicit fence is not necessary?Upvotes: 0
Views: 59