https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66553
--- Comment #3 from Julian Taylor <jtaylor.debian at googlemail dot com> --- Would adding a libgomp threadsanitizer configure switch be an option? It could enable --disable-linux-futex which you need for omp critical sections, set the right compile and link flags and add some extra locks in the task structure to remove the false positives. note gcc 6.2 still produces thread sanitizer errors with the above example when using tasks: ================== WARNING: ThreadSanitizer: data race (pid=12405) Write of size 4 at 0x7d880001c900 by thread T1 (mutexes: write M12): #0 gomp_team_barrier_set_task_pending ../libgomp/config/posix/bar.h:125 (libgomp.so.1+0x00000001bd5b) #1 GOMP_task ../libgomp/task.c:455 (libgomp.so.1+0x00000001bd5b) #2 main._omp_fn.0 /tmp/jtaylor/test2.c:17 (a.out+0x000000400aff) #3 gomp_thread_start ../libgomp/team.c:119 (libgomp.so.1+0x000000022860) Previous read of size 4 at 0x7d880001c900 by thread T4 (mutexes: write M11): #0 gomp_barrier_wait_start ../libgomp/config/posix/bar.h:82 (libgomp.so.1+0x00000002619b) #1 gomp_team_barrier_wait ../libgomp/config/posix/bar.c:252 (libgomp.so.1+0x00000002619b) #2 gomp_team_barrier_wait_final ../libgomp/config/posix/bar.h:104 (libgomp.so.1+0x00000002286c) #3 gomp_thread_start ../libgomp/team.c:120 (libgomp.so.1+0x00000002286c) Location is heap block of size 5440 at 0x7d880001c800 allocated by main thread: #0 malloc ../../../../libsanitizer/tsan/tsan_interceptors.cc:538 (libtsan.so.0+0x0000000298bc) #1 gomp_malloc ../libgomp/alloc.c:37 (libgomp.so.1+0x00000000b06a) #2 gomp_new_team ../libgomp/team.c:168 (libgomp.so.1+0x0000000228fa) #3 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129e3) #4 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Mutex M12 (0x7d880001cf40) created at: #0 pthread_mutex_init ../../../../libsanitizer/tsan/tsan_interceptors.cc:1091 (libtsan.so.0+0x00000002b4be) #1 gomp_mutex_init ../libgomp/config/posix/mutex.h:40 (libgomp.so.1+0x00000002291a) #2 gomp_new_team ../libgomp/team.c:174 (libgomp.so.1+0x00000002291a) #3 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129e3) #4 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Mutex M11 (0x7d880001c890) created at: #0 pthread_mutex_init ../../../../libsanitizer/tsan/tsan_interceptors.cc:1091 (libtsan.so.0+0x00000002b4be) #1 gomp_mutex_init ../libgomp/config/posix/mutex.h:40 (libgomp.so.1+0x000000025bde) #2 gomp_barrier_init ../libgomp/config/posix/bar.c:37 (libgomp.so.1+0x000000025bde) #3 gomp_new_team ../libgomp/team.c:173 (libgomp.so.1+0x00000002290b) #4 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129e3) #5 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Thread T1 (tid=12407, running) created by main thread at: #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors.cc:876 (libtsan.so.0+0x00000002ad6d) #1 gomp_team_start ../libgomp/team.c:806 (libgomp.so.1+0x0000000231cd) #2 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129f7) #3 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Thread T4 (tid=12410, running) created by main thread at: #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors.cc:876 (libtsan.so.0+0x00000002ad6d) #1 gomp_team_start ../libgomp/team.c:806 (libgomp.so.1+0x0000000231cd) #2 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129f7) #3 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) SUMMARY: ThreadSanitizer: data race ../libgomp/config/posix/bar.h:125 in gomp_team_barrier_set_task_pending ================== 2 0 ================== WARNING: ThreadSanitizer: data race (pid=12405) Read of size 4 at 0x7d880001cf88 by thread T1: #0 GOMP_task ../libgomp/task.c:318 (libgomp.so.1+0x00000001b69a) #1 main._omp_fn.0 /tmp/jtaylor/test2.c:17 (a.out+0x000000400aff) #2 gomp_thread_start ../libgomp/team.c:119 (libgomp.so.1+0x000000022860) Previous write of size 4 at 0x7d880001cf88 by thread T2 (mutexes: write M12): #0 gomp_barrier_handle_tasks ../libgomp/task.c:1295 (libgomp.so.1+0x0000000178be) #1 gomp_team_barrier_wait_end ../libgomp/config/posix/bar.c:155 (libgomp.so.1+0x000000025f15) #2 gomp_team_barrier_wait ../libgomp/config/posix/bar.c:252 (libgomp.so.1+0x0000000261db) #3 gomp_team_barrier_wait_final ../libgomp/config/posix/bar.h:104 (libgomp.so.1+0x00000002286c) #4 gomp_thread_start ../libgomp/team.c:120 (libgomp.so.1+0x00000002286c) Location is heap block of size 5440 at 0x7d880001c800 allocated by main thread: #0 malloc ../../../../libsanitizer/tsan/tsan_interceptors.cc:538 (libtsan.so.0+0x0000000298bc) #1 gomp_malloc ../libgomp/alloc.c:37 (libgomp.so.1+0x00000000b06a) #2 gomp_new_team ../libgomp/team.c:168 (libgomp.so.1+0x0000000228fa) #3 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129e3) #4 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Mutex M12 (0x7d880001cf40) created at: #0 pthread_mutex_init ../../../../libsanitizer/tsan/tsan_interceptors.cc:1091 (libtsan.so.0+0x00000002b4be) #1 gomp_mutex_init ../libgomp/config/posix/mutex.h:40 (libgomp.so.1+0x00000002291a) #2 gomp_new_team ../libgomp/team.c:174 (libgomp.so.1+0x00000002291a) #3 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129e3) #4 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Thread T1 (tid=12407, running) created by main thread at: #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors.cc:876 (libtsan.so.0+0x00000002ad6d) #1 gomp_team_start ../libgomp/team.c:806 (libgomp.so.1+0x0000000231cd) #2 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129f7) #3 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) Thread T2 (tid=12408, running) created by main thread at: #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors.cc:876 (libtsan.so.0+0x00000002ad6d) #1 gomp_team_start ../libgomp/team.c:806 (libgomp.so.1+0x0000000231cd) #2 GOMP_parallel ../libgomp/parallel.c:167 (libgomp.so.1+0x0000000129f7) #3 main /tmp/jtaylor/test2.c:11 (a.out+0x000000400a70) SUMMARY: ThreadSanitizer: data race ../libgomp/task.c:318 in GOMP_task ================== 3 1 ThreadSanitizer: reported 2 warnings