Skip to content

Commit

Permalink
Fix bug that blocks the data loader when not all batches in the queue…
Browse files Browse the repository at this point in the history
… are consumed
  • Loading branch information
lauracanalini committed Mar 8, 2022
1 parent 5aa2785 commit 83112f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions modules/eddl/include/ecvl/support_eddl.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ class ProducersConsumerQueue
cond_notempty_.notify_one();
}

/** @brief Free threads locked on a push operation.
Notifies all the locked threads on the condition variable cond_notfull_ that were waiting to retake the control in the
critical region of pushing new elements in to the queue.
This method is specific to be used in the Stop() operation when the data loading process needs to be stopped before all
the elements (batches) of the queue have been consumed.
*/
void FreeLockedOnPush()
{
cond_notfull_.notify_all();
}

/** @brief Pop a sample from the queue.
Take the lock of the queue and wait if the queue is empty. Otherwise, pop a sample, an image and its label from the queue.
Expand Down
7 changes: 6 additions & 1 deletion modules/eddl/src/support_eddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ void DLDataset::Stop()
ECVL_ERROR_STOP_ALREADY_END
}

active_ = false;
{
std::unique_lock<std::mutex> lock(active_mutex_);
active_ = false;
queue_.FreeLockedOnPush();
}

for (auto i = 0u; i < num_workers_; ++i) {
producers_[i].join();
}
Expand Down

0 comments on commit 83112f6

Please sign in to comment.