diff --git a/drama/src/rev-mc.c b/drama/src/rev-mc.c index 0823a3f..ed00035 100644 --- a/drama/src/rev-mc.c +++ b/drama/src/rev-mc.c @@ -362,19 +362,24 @@ find_row_mask(std::vector &sets, } diff -= std::min(inner_step, diff); - std::lock_guard _(lock); if (end_pos - diff > g_base_pos) { + std::lock_guard _(lock); if (found) { break; } - g_base_pos = end_pos - diff; - row_mask = cur_mask; + if (end_pos - diff > g_base_pos) { + g_base_pos = end_pos - diff; + row_mask = cur_mask; + } } else if (end_pos >= g_base_pos) { - diff = end_pos - g_base_pos; - cur_mask = row_mask; + std::lock_guard _(lock); + if (end_pos >= g_base_pos) { + diff = end_pos - g_base_pos; + cur_mask = row_mask; + } } } for (int i = outer_step; i > 0 && cur_mask < last_mask; --i) { - if (resolve(cur_mask)) { + if (resolve(cur_mask) && !found) { bool expected = false; if (found.compare_exchange_strong(expected, true)) { std::lock_guard _(lock);