diff --git a/drama/src/rev-mc.c b/drama/src/rev-mc.c index 1feda2b..95adb6c 100644 --- a/drama/src/rev-mc.c +++ b/drama/src/rev-mc.c @@ -304,9 +304,10 @@ find_row_mask(std::vector &sets, const uint64_t last_mask = (row_mask << (40 - 16)); row_mask <<= CL_SHIFT;// skip the lowest 6 bits since they're used for CL addressing - auto resolve = [=](uint64_t row_mask) -> bool { + auto resolve = [=](uint64_t row_mask, std::atomic &stopped) -> bool { if (row_mask & LS_BITMASK(CL_SHIFT)) { return false; } for (auto addr_pool : same_row_sets) { + if (stopped.load(std::memory_order_relaxed)) { return false; } addr_tuple base_addr = addr_pool[0]; for (int i = 1; i < addr_pool.size(); i++) { addr_tuple tmp = addr_pool[i]; @@ -325,9 +326,9 @@ find_row_mask(std::vector &sets, row_mask = next_bit_permutation(row_mask); } - std::vector worker; + std::vector workers; for (int i = 0; i < 8; ++i) { - worker.emplace_back([&] { + workers.emplace_back([&] { while (!found) { uint64_t cur_mask; { @@ -338,16 +339,19 @@ find_row_mask(std::vector &sets, verbose_printerr("[LOG] - Row mask: 0x%0lx \t\t bits: %s\n", cur_mask, bit_string(cur_mask)); } - if (resolve(cur_mask)) { + if (resolve(cur_mask, found)) { std::lock_guard _(lock); - found.store(true); - row_mask = cur_mask; - while (!mask_task.empty()) mask_task.pop(); + if (!found.exchange(true)) { + row_mask = cur_mask; + while (!mask_task.empty()) mask_task.pop(); + } } } }); } + for (auto &worker : workers) { worker.join(); } + // super hackish way to recover the real row mask for (auto m : fn_masks) { uint64_t lsb = (1 << (__builtin_ctzl(m) + 1));