aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2013-03-23 21:51:38 +0200
committerLasse Collin <lasse.collin@tukaani.org>2013-03-23 21:51:38 +0200
commite572e123b55b29527e54ce5f0807f115481d78b9 (patch)
tree3c64b954d1b8bf0b70119596f5cc4dddf19f1b67 /src/liblzma/common
parentliblzma: Add lzma_block_uncomp_encode(). (diff)
downloadxz-e572e123b55b29527e54ce5f0807f115481d78b9.tar.xz
liblzma: Fix another deadlock in the threaded encoder.
This race condition could cause a deadlock if lzma_end() was called before finishing the encoding. This can happen with xz with debugging enabled (non-debugging version doesn't call lzma_end() before exiting).
Diffstat (limited to 'src/liblzma/common')
-rw-r--r--src/liblzma/common/stream_encoder_mt.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/liblzma/common/stream_encoder_mt.c b/src/liblzma/common/stream_encoder_mt.c
index 3199cf80..e30e9dca 100644
--- a/src/liblzma/common/stream_encoder_mt.c
+++ b/src/liblzma/common/stream_encoder_mt.c
@@ -341,11 +341,14 @@ worker_start(void *thr_ptr)
if (state == THR_EXIT)
break;
- // Mark the thread as idle. Signal is needed for the case
+ // Mark the thread as idle unless the main thread has
+ // told us to exit. Signal is needed for the case
// where the main thread is waiting for the threads to stop.
mythread_sync(thr->mutex) {
- thr->state = THR_IDLE;
- pthread_cond_signal(&thr->cond);
+ if (thr->state != THR_EXIT) {
+ thr->state = THR_IDLE;
+ pthread_cond_signal(&thr->cond);
+ }
}
mythread_sync(thr->coder->mutex) {