]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstdmt: fixed minor race condition
authorYann Collet <cyan@fb.com>
Tue, 23 Jan 2018 22:03:07 +0000 (14:03 -0800)
committerYann Collet <cyan@fb.com>
Tue, 23 Jan 2018 22:03:07 +0000 (14:03 -0800)
no real consequence, but pollute tsan tests :

job->dstBuff is being modified inside worker,
while main thread might read it accidentally
because it copies whole job.
But since it doesn't used dstBuff, there is no real consequence.

Other potential solution : only copy useful data, instead of whole job

lib/compress/zstdmt_compress.c

index be683e83ff0be262503b00c613ab0c540907e36a..922839810d712d714ffa05e1cc3d6c5ca0d7de67 100644 (file)
@@ -344,7 +344,9 @@ void ZSTDMT_compressChunk(void* jobDescription)
             job->cSize = ERROR(memory_allocation);
             goto _endJob;
         }
+        ZSTD_PTHREAD_MUTEX_LOCK(job->jobCompleted_mutex);   /* note : it's a mtctx mutex */
         job->dstBuff = dstBuff;
+        ZSTD_pthread_mutex_unlock(job->jobCompleted_mutex);
     }
 
     /* init */