std::atomic
¶
Atomic Instructions (1)¶
Simple integers don’t need a mutex ⟶ atomic instructions
static int global;
void inc() {
__sync_fetch_and_add(&global, 1);
}
static LONG global;
void inc() {
InterlockedIncrement(&global);
}
Atomic Instructions (2)¶
#include <atomic>
std::atomic<int> global(0);
void inc() {
global++;
}
Specializations for all types that are capable