gcc -fsanitize=thread -fPIE -pie -g -o a a.c -lpthread
执行a程序:
[root@localhost nan]# ./a==================WARNING: ThreadSanitizer: data race (pid=14545) Write of size 4 at 0x7f055b4802b0 by thread T1: #0 Thread1 /home/nan/a.c:4 (a+0x000000000a87) Previous write of size 4 at 0x7f055b4802b0 by main thread: #0 main /home/nan/a.c:10 (a+0x000000000ae8) Location is global 'Global' of size 4 at 0x7f055b4802b0 (a+0x0000002012b0) Thread T1 (tid=14547, running) created by main thread at: #0 pthread_create /opt/gcc-4.9.2/src/gcc-4.9.2/libsanitizer/tsan/tsan_interceptors.cc:877 (libtsan.so.0+0x00000004aa83) #1 main /home/nan/a.c:9 (a+0x000000000ad9)SUMMARY: ThreadSanitizer: data race /home/nan/a.c:4 Thread1==================ThreadSanitizer: reported 1 warnings