Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix race condition in engine start/stop #8995

Merged
merged 1 commit into from
Dec 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/engine/threaded_engine_perdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ class ThreadedEnginePerDevice : public ThreadedEngine {
int cpu_priority_nthreads = dmlc::GetEnv("MXNET_CPU_PRIORITY_NTHREADS", 4);
cpu_priority_worker_.reset(new ThreadWorkerBlock<kPriorityQueue>());
cpu_priority_worker_->pool.reset(new ThreadPool(
cpu_priority_nthreads, [this]() {
this->CPUWorker(Context(), cpu_priority_worker_.get());
}));
cpu_priority_nthreads,
[this](std::shared_ptr<ThreadPool::SimpleEvent> ready_event) {
this->CPUWorker(Context(), cpu_priority_worker_.get(), ready_event);
}, true));
// GPU tasks will be created lazily
}

Expand All @@ -122,9 +123,10 @@ class ThreadedEnginePerDevice : public ThreadedEngine {
auto ptr =
cpu_normal_workers_.Get(dev_id, [this, ctx, nthread]() {
auto blk = new ThreadWorkerBlock<kWorkerQueue>();
blk->pool.reset(new ThreadPool(nthread, [this, ctx, blk] () {
this->CPUWorker(ctx, blk);
}));
blk->pool.reset(new ThreadPool(nthread,
[this, ctx, blk](std::shared_ptr<ThreadPool::SimpleEvent> ready_event) {
this->CPUWorker(ctx, blk, ready_event);
}, true));
return blk;
});
if (ptr) {
Expand Down Expand Up @@ -259,12 +261,14 @@ class ThreadedEnginePerDevice : public ThreadedEngine {
*/
template<dmlc::ConcurrentQueueType type>
inline void CPUWorker(Context ctx,
ThreadWorkerBlock<type> *block) {
ThreadWorkerBlock<type> *block,
std::shared_ptr<ThreadPool::SimpleEvent> ready_event) {
this->is_worker_ = true;
auto* task_queue = &(block->task_queue);
RunContext run_ctx{ctx, nullptr};
// execute task
OprBlock* opr_block;
ready_event->signal();
while (task_queue->Pop(&opr_block)) {
this->ExecuteOprBlock(run_ctx, opr_block);
}
Expand Down