90e304
--- a/squashfs-tools/mksquashfs.c
90e304
+++ b/squashfs-tools/mksquashfs.c
90e304
@@ -2447,8 +2447,8 @@ void *frag_deflator(void *arg)
90e304
 			write_buffer->block = bytes;
90e304
 			bytes += compressed_size;
90e304
 			fragments_outstanding --;
90e304
-			pthread_mutex_unlock(&fragment_mutex);
90e304
 			queue_put(to_writer, write_buffer);
90e304
+			pthread_mutex_unlock(&fragment_mutex);
90e304
 			TRACE("Writing fragment %lld, uncompressed size %d, "
90e304
 				"compressed size %d\n", file_buffer->block,
90e304
 				file_buffer->size, compressed_size);
90e304