Are monotonic properties of std::chrono::steady_clock
preserved across threads? For example, suppose I have the following program.
#include <chrono>
#include <mutex>
#include <thread>
using namespace std;
using namespace chrono;
mutex m;
int i = 0;
void do_something(int &x) {
x += 1;
}
void f1() {
unique_lock<mutex> lock(m);
auto time = steady_clock::now();
do_something(i);
}
void f2() {
unique_lock<mutex> lock(m);
auto time = steady_clock::now();
do_something(i);
}
int main() {
thread t1(f1);
thread t2(f2);
t1.join();
t2.join();
return 0;
}
Can I assume that the thread that has the smaller time
value in the end (supposing they have different value at all) modified i
before the other and that the other saw i
as it was left by the first one?