#include #include using namespace std::literals; int v[20]; // sizeof(v[20]) == 80 bytes > cache line template static 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}, {"b", b}}); } BENCHMARK(f); // false sharing :( BENCHMARK(f); // true sharing :) BENCHMARK_MAIN();