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

Fix memory error in threaded engine #6084

Merged
merged 1 commit into from
May 3, 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
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