提交 6decbdf4 编写于 作者: E emailweixu 提交者: Yu Yang

Fix potential dead lock in PyDataProvider2 (#140)

This bug occasionally causes dead lock in test_RecurrentGradientMachine
In general, conditional_variable::notify should be used together with mutex for changing condition.
上级 4615c517
...@@ -377,9 +377,15 @@ private: ...@@ -377,9 +377,15 @@ private:
std::swap(callingContexts_[cid], callingContexts_[0]); std::swap(callingContexts_[cid], callingContexts_[0]);
cid = 0; cid = 0;
} }
PyObjectPtr front;
{
std::unique_lock<std::mutex> l(mtx_);
front = pop_get_front(callingContexts_);
}
{ {
PyGuard g; PyGuard g;
callingContexts_.pop_front(); front.reset();
} }
this->pullCV_.notify_all(); this->pullCV_.notify_all();
continue; continue;
...@@ -411,10 +417,7 @@ private: ...@@ -411,10 +417,7 @@ private:
poolActualSize_ += additionalBatchSize; poolActualSize_ += additionalBatchSize;
dataPool_.emplace_back(data); dataPool_.emplace_back(data);
} }
pullCV_.notify_all();
{
pullCV_.notify_all();
}
} }
DBG << "load thread end"; DBG << "load thread end";
} }
......
...@@ -191,7 +191,7 @@ void installFailureWriter(void(*callback)(const char*, int)); ...@@ -191,7 +191,7 @@ void installFailureWriter(void(*callback)(const char*, int));
} }
#endif // PADDLE_USE_GLOG #endif // PADDLE_USE_GLOG
#ifndef NDEBUG #ifdef NDEBUG
#define DEBUG_LEVEL 5 #define DEBUG_LEVEL 5
#define DBG VLOG(DEBUG_LEVEL) #define DBG VLOG(DEBUG_LEVEL)
#else #else
......
...@@ -112,6 +112,17 @@ static bool contains(const Container& container, const T& val) { ...@@ -112,6 +112,17 @@ static bool contains(const Container& container, const T& val) {
return std::find(container.begin(), container.end(), val) != container.end(); return std::find(container.begin(), container.end(), val) != container.end();
} }
/**
* pop and get the front element of a container
*/
template<typename Container>
typename Container::value_type pop_get_front(Container& c) {
typename Container::value_type v;
swap(v, c.front());
c.pop_front();
return v;
}
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a))) #define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册