I mean compared with c++11 atomic, for example:
#include <iostream>#include <thread>#include <atomic>std::atomic<int> counter(0);void incrementCounter() { for (int i = 0; i < 1000; ++i) { counter.fetch_add(1, std::memory_order_relaxed); }}int main() { std::thread t1(incrementCounter); std::thread t2(incrementCounter); t1.join(); t2.join(); std::cout << "Final counter value: " << counter << std::endl; return 0;}
In the usage of std::atomic, we need to pass memory order parameters. Why doesn't std::mutex have this parameter and what's the default memory order of std::mutex?