-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 SRL hang when exit. #291
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.pyc | ||
train.log | ||
data/feature | ||
data/conll05st-release/ | ||
data/src.dict | ||
data/test.wsj.props | ||
data/test.wsj.seq_pair | ||
data/test.wsj.words | ||
data/tgt.dict | ||
output |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ class IPyDataProviderCache { | |
* Here, we start a thread to read data. It is totally asynchronous for reading | ||
* data. And it support cache strategies. | ||
*/ | ||
class PyDataProvider2 : public DataProvider { | ||
class PyDataProvider2 : public DataProvider, private WaitMethodDone { | ||
public: | ||
/** | ||
* Ctor | ||
|
@@ -433,26 +433,33 @@ class PyDataProvider2 : public DataProvider { | |
|
||
inline void resetImpl(bool startNewThread) { | ||
DBG << "Reseting " << startNewThread; | ||
exit_.store(true); | ||
if (loadThread_) { // is loading. | ||
exit_.store(true); | ||
loadThread_->join(); | ||
loadThread_.reset(); | ||
} | ||
{ | ||
PyGuard g; | ||
callingContexts_.clear(); | ||
this->pullCV_.notify_one(); | ||
} | ||
this->waitNotCalling(); | ||
{ | ||
PyGuard g; | ||
dataPool_.clear(); | ||
} | ||
poolActualSize_ = 0; | ||
exit_ = false; | ||
|
||
if (startNewThread && cache_->reset()) { | ||
DBG << "Start new thread."; | ||
loadThread_.reset(new std::thread([this] { | ||
exit_ = false; | ||
loadThread(); | ||
})); | ||
callingContextCreated_.wait(); | ||
} | ||
DBG << "Reset done"; | ||
exit_ = false; | ||
} | ||
|
||
private: | ||
|
@@ -529,6 +536,7 @@ class PyDataProvider2 : public DataProvider { | |
* Loading a batch of data. | ||
*/ | ||
int64_t getNextBatchInternal(int64_t size_, DataBatch *batch) { | ||
auto guard = this->guard(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like mutex can support it. Why need guard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 也许可以,我试试 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, mutex should work |
||
REGISTER_TIMER("PyDP2.getNextBatchInternal") | ||
CHECK_GE(size_, 0); | ||
size_t size = (size_t) size_; | ||
|
@@ -554,6 +562,10 @@ class PyDataProvider2 : public DataProvider { | |
} else { // loading from cache. | ||
poolPtr = this->cache_->load(); | ||
} | ||
if (exit_) { | ||
// PyDataProvider is destructing. | ||
return 0; | ||
} | ||
CHECK(poolPtr != nullptr); | ||
|
||
std::deque<PyObjectPtr>& pool = *poolPtr; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add
&& !stopping_
here. Whether only the beginning will appearbatchSize_ == 0
.The compiler may be optimized line 132 and 137, try define stopping_ with volatile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有一种情况,即dataprovider一次都没被调用过,就直接退出。。batch size是0,stopping是true