File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -50,13 +50,16 @@ TEST(Parallel, ForEachThread) {
5050TEST (ThreadLocal, Consistency) {
5151 ThreadLocal<std::thread::id> tids ([]() { return std::this_thread::get_id (); });
5252
53- auto busywork = [](int64_t index) {
53+ std::atomic<int64_t > dummy{0 };
54+ auto busywork = [&dummy](int64_t index) {
5455 // Do some busy work to burn some time
55- Float f = 1.141 ;
56+ // Use the index to do a varying amount of computation
57+ int64_t result = 0 ;
5658 for (int i = 0 ; i <= index; ++i)
5759 for (int j = 0 ; j <= index; ++j)
58- f *= std::sqrt (f);
59- EXPECT_NE (f, 1 .141f ); // make sure it isn't optimized out
60+ result += i * j;
61+ // Store result in atomic to prevent optimization
62+ dummy.fetch_add (result, std::memory_order_relaxed);
6063 };
6164
6265 ParallelFor (0 , 1000 , [&](int64_t index) {
You can’t perform that action at this time.
0 commit comments