mirror of
https://github.com/facebook/zstd.git
synced 2025-07-28 00:01:53 +03:00
[contrib/pzstd] Prevent hangs when there are errors
When two threads are using a WorkQueue and the reader thread exits due to an error, it must call WorkQueue::finish() to wake up the writer thread. Otherwise, if the queue is full and the writer thread is waiting for a free slot, it could hang forever. This can happen in pratice when decompressing a large, corrupted file that does not contain pzstd skippable frames.
This commit is contained in:
committed by
Nick Terrell
parent
a610550e2c
commit
80af41e08a
@ -115,13 +115,14 @@ class WorkQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* Promise that `push()` won't be called again, so once the queue is empty
|
||||
* there will never any more work.
|
||||
* Promise that either the reader side or the writer side is done.
|
||||
* If the writer is done, `push()` won't be called again, so once the queue
|
||||
* is empty there will never be any more work. If the reader is done, `pop()`
|
||||
* won't be called again, so further items pushed will just be ignored.
|
||||
*/
|
||||
void finish() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
assert(!done_);
|
||||
done_ = true;
|
||||
}
|
||||
readerCv_.notify_all();
|
||||
|
Reference in New Issue
Block a user