For example: WARNING: ThreadSanitizer: data race (pid=14665) Write of size 4 at 0x7b1c00007890 by thread T99: #0 worker_thread util/thread-pool.c:112:20 (qemu-system-aarch64+0xd52108) #1 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd5be30)
Previous read of size 4 at 0x7b1c00007890 by main thread (mutexes: write M875, write M897): #0 thread_pool_completion_bh util/thread-pool.c:177:19 (qemu-system-aarch64+0xd51a73) #1 aio_bh_call util/async.c:136:5 (qemu-system-aarch64+0xd4f98e) #2 aio_bh_poll util/async.c:164:13 (qemu-system-aarch64+0xd4f98e) Signed-off-by: Robert Foley <robert.fo...@linaro.org> --- util/thread-pool.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/thread-pool.c b/util/thread-pool.c index d763cea505..2403669827 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -21,6 +21,7 @@ #include "trace.h" #include "block/thread-pool.h" #include "qemu/main-loop.h" +#include "qemu/tsan.h" static void do_spawn_thread(ThreadPool *pool); @@ -97,7 +98,9 @@ static void *worker_thread(void *opaque) } req = QTAILQ_FIRST(&pool->request_list); + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); QTAILQ_REMOVE(&pool->request_list, req, reqs); + req->state = THREAD_ACTIVE; qemu_mutex_unlock(&pool->lock); @@ -107,7 +110,7 @@ static void *worker_thread(void *opaque) /* Write ret before state. */ smp_wmb(); req->state = THREAD_DONE; - + TSAN_ANNOTATE_IGNORE_WRITES_END(); qemu_mutex_lock(&pool->lock); qemu_bh_schedule(pool->completion_bh); -- 2.17.1