Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential dead lock in PyDataProvider2 #139

Closed
Closed
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions paddle/gserver/dataproviders/PyDataProvider2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,17 @@ class PyDataProvider2 : public DataProvider {
std::swap(callingContexts_[cid], callingContexts_[0]);
cid = 0;
}

PyObjectPtr front;
{
std::unique_lock<std::mutex> l(mtx_);
front = pop_get_front(callingContexts_);
this->pullCV_.notify_all();
}
{
PyGuard g;
callingContexts_.pop_front();
front.reset();
}
this->pullCV_.notify_all();
continue;
}
}
Expand Down Expand Up @@ -410,9 +416,6 @@ class PyDataProvider2 : public DataProvider {
std::lock_guard<std::mutex> guard(mtx_);
poolActualSize_ += additionalBatchSize;
dataPool_.emplace_back(data);
}

{
pullCV_.notify_all();
}
}
Expand Down Expand Up @@ -592,8 +595,8 @@ class PyDataProvider2 : public DataProvider {
{
std::lock_guard<std::mutex> g(mtx_);
poolActualSize_ -= bsize;
this->pushCV_.notify_all();
}
this->pushCV_.notify_all();
}

if (bsize == 0) { // end of pass. In data pool, cannot get any data.
Expand Down
2 changes: 1 addition & 1 deletion paddle/utils/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void installFailureWriter(void(*callback)(const char*, int));
}
#endif // PADDLE_USE_GLOG

#ifndef NDEBUG
#ifdef NDEBUG
#define DEBUG_LEVEL 5
#define DBG VLOG(DEBUG_LEVEL)
#else
Expand Down
11 changes: 11 additions & 0 deletions paddle/utils/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ static bool contains(const Container& container, const T& val) {
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)))

/**
Expand Down