Skip to content

Commit

Permalink
Make sure to lock when reading the keep_sampling variable
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Lampacrescia <[email protected]>
  • Loading branch information
MarcoLm993 committed Aug 9, 2024
1 parent db115e5 commit 76e3fb3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/samples/sampling_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,15 @@ double SamplingResults::getProbabilityVerifiedProperty() const {

bool SamplingResults::newBatchNeeded(const size_t thread_id) const {
// Check if the buffer for the thread is full. Wait for a slot to be available in case
if (_keep_sampling) {
_results_buffer.waitForSlotAvailable(thread_id);
{
std::scoped_lock<std::mutex> lock(_mtx);
if (!_keep_sampling) {
return false;
}
}
_results_buffer.waitForSlotAvailable(thread_id);
// The result might be available in the meanwhile, so use the _keep_sampling as return
std::scoped_lock<std::mutex> lock(_mtx);
return _keep_sampling;
}

Expand Down

0 comments on commit 76e3fb3

Please sign in to comment.