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 #140

Merged
merged 1 commit into from
Sep 29, 2016
Merged
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
13 changes: 8 additions & 5 deletions paddle/gserver/dataproviders/PyDataProvider2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,15 @@ class PyDataProvider2 : public DataProvider {
std::swap(callingContexts_[cid], callingContexts_[0]);
cid = 0;
}

PyObjectPtr front;
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add item or to remove item to callingContexts_ is always under PyGuard. And getting size of this container always in same thread. It seems that there is no dead lock here.

std::unique_lock<std::mutex> l(mtx_);
front = pop_get_front(callingContexts_);
}
{
PyGuard g;
callingContexts_.pop_front();
front.reset();
}
this->pullCV_.notify_all();
continue;
Expand Down Expand Up @@ -411,10 +417,7 @@ class PyDataProvider2 : public DataProvider {
poolActualSize_ += additionalBatchSize;
dataPool_.emplace_back(data);
}

{
pullCV_.notify_all();
}
pullCV_.notify_all();
}
DBG << "load thread end";
}
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
Copy link
Collaborator

@reyoung reyoung Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means DBG will be disabled when release. And when debug, it just like VLOG(5).

It may harm release performance to enable it in release.

#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