Skip to content

Commit

Permalink
Fix memory error in threaded engine (apache#6084)
Browse files Browse the repository at this point in the history
  • Loading branch information
sifmelcara authored and tqchen committed May 3, 2017
1 parent c9841c1 commit 3395d1d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/engine/threaded_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ void ThreadedEngine::WaitForAll() {
}

inline void ThreadedEngine::OnComplete(ThreadedOpr* threaded_opr) {
bool is_temporary_opr = threaded_opr->temporary;
// Mark complete for read variables
for (auto&& i : threaded_opr->const_vars) {
i->CompleteReadDependency([this](OprBlock* opr) {
Expand Down Expand Up @@ -376,6 +377,10 @@ inline void ThreadedEngine::OnComplete(ThreadedOpr* threaded_opr) {
ThreadedVar::Delete(i);
}
}
// The function been pushed from `ThreadedEngine::DeleteOperator`
// could execute right after we mark all vars as complete, so if
// threaded_opr is not temporary, its value is not reliable
// anymore start from here.
int npending;
{
std::unique_lock<std::mutex> lock{finished_m_};
Expand All @@ -388,7 +393,7 @@ inline void ThreadedEngine::OnComplete(ThreadedOpr* threaded_opr) {
}

// delte operator if it is temperory
if (threaded_opr->temporary) {
if (is_temporary_opr) {
ThreadedOpr::Delete(threaded_opr);
}
}
Expand Down

0 comments on commit 3395d1d

Please sign in to comment.