#include #include #include using namespace std::literals; std::atomic v[10]; // sizeof(v[10]) = 80B template &a, std::atomic &b> void f(benchmark::State &state) { for (auto _ : state) { std::atomic run = true; a = b = 0; std::jthread j1([&](){ while (run) ++a; }), j2([&](){ while (run) ++b; }); std::this_thread::sleep_for(100us); run = false; } state.counters.insert({{"a", a.load()}, {"b", b.load()}}); } BENCHMARK(f); // false sharing :( BENCHMARK(f); // no false sharing :) BENCHMARK_MAIN();