http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40362
--- Comment #10 from Dmitry Vyukov <dvyukov at google dot com> 2012-12-29 10:28:06 UTC --- ThreadSanitizer says the same: Testcase: !$OMP PARALLEL PRIVATE(j) j=OMP_GET_THREAD_NUM() ! no warnings without the dynamic schedule !$OMP DO SCHEDULE(DYNAMIC,2) DO i=1,10 ENDDO !$OMP END PARALLEL END Result: vjo...@nanosim-s01.ethz.ch:/data/vjoost/clean/cp2k/cp2k/src> ./a.out vjo...@nanosim-s01.ethz.ch:/data/vjoost/clean/cp2k/cp2k/src> ./a.out vjo...@nanosim-s01.ethz.ch:/data/vjoost/clean/cp2k/cp2k/src> ./a.out vjo...@nanosim-s01.ethz.ch:/data/vjoost/clean/cp2k/cp2k/src> ./a.out ================== WARNING: ThreadSanitizer: data race (pid=35190) Read of size 8 at 0x7d3000027290 by main thread: #0 gomp_iter_dynamic_next /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/iter.c:190 (libgomp.so.1+0x000000006678) #1 GOMP_loop_dynamic_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/loop.c:128 (libgomp.so.1+0x000000007a03) #2 MAIN__._omp_fn.0 test.f90:0 (exe+0x000000000d7d) #3 MAIN__ test.f90:0 (exe+0x000000000ccb) #4 main ??:0 (exe+0x000000000d1a) Previous write of size 8 at 0x7d3000027290 by thread 1: #0 gomp_loop_init /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/loop.c:41 (libgomp.so.1+0x000000007a96) #1 MAIN__._omp_fn.0 test.f90:0 (exe+0x000000000d7d) #2 gomp_thread_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/team.c:116 (libgomp.so.1+0x00000000d012) Location is heap block of size 1568 at 0x7d3000027100 allocated by main thread: #0 malloc ??:0 (libtsan.so.0+0x00000001896e) #1 gomp_malloc /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/alloc.c:36 (libgomp.so.1+0x00000000417a) #2 gomp_new_team /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/team.c:145 (libgomp.so.1+0x00000000d27a) #3 GOMP_parallel_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/parallel.c:108 (libgomp.so.1+0x00000000afc7) #4 MAIN__ test.f90:0 (exe+0x000000000cc1) #5 main ??:0 (exe+0x000000000d1a) Thread 1 (tid=35191, running) created at: #0 pthread_create ??:0 (libtsan.so.0+0x00000001a868) #1 gomp_team_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/team.c:440 (libgomp.so.1+0x00000000d908) #2 GOMP_parallel_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/parallel.c:108 (libgomp.so.1+0x00000000afd7) #3 MAIN__ test.f90:0 (exe+0x000000000cc1) #4 main ??:0 (exe+0x000000000d1a) gomp_ptrlock_get() function is not thread-safe. It's not only about atomicity, it's also about memory ordering. Thread that calls gomp_ptrlock_set() can reorder stores to ws and the store to ptrlock->ptr. Alpha processors can even reorder load from ws and load of ptrlock->ptr (they do not respect data dependencies).