diff --git a/drama/src/rev-mc.c b/drama/src/rev-mc.c index 7d7215a..876ccbf 100644 --- a/drama/src/rev-mc.c +++ b/drama/src/rev-mc.c @@ -346,14 +346,15 @@ find_row_mask(std::vector &sets, for (int i = 0; i < thread_num; ++i) { workers.emplace_back([&] { while (!found) { - uint64_t cur_mask = last_mask; + uint64_t cur_mask = 0; uint64_t step_count = 0; uint64_t my_pos = 0; { std::lock_guard _(lock); - if (row_mask >= last_mask || found) { break; } - cur_mask = row_mask; + if (row_mask >= last_mask || found) { return; } step_count = g_cur_pos - g_base_pos; + + cur_mask = row_mask; my_pos = g_cur_pos.fetch_add(step); } while (cur_mask < last_mask && step_count > 0 && !found.load(std::memory_order_relaxed)) { @@ -369,15 +370,15 @@ find_row_mask(std::vector &sets, step_count -= std::min(step_count, step); - if (my_pos > g_base_pos.load(std::memory_order_relaxed)) { + if (my_pos > g_base_pos.load(std::memory_order_relaxed) + step_count) { std::lock_guard _(lock); - if (my_pos > g_base_pos) { + if (my_pos > g_base_pos + step_count) { g_base_pos = my_pos; row_mask = cur_mask; } - } else if (g_base_pos.load(std::memory_order_relaxed) < my_pos) { + } else { std::lock_guard _(lock); - if (g_base_pos <= my_pos) { + if (g_base_pos + step_count <= my_pos) { cur_mask = row_mask; step_count = my_pos - g_base_pos; }