The User Concurrency Sanitizer (UCSAN) is the watchpoint-based data race detector. It uses the thread sanitizer interface in Clang (v3.2+) and GCC (v4.8+) to determine whether the variable data race.
Currently, it only will check the non-volatile type of variable access. In other words, all the variables with thread-safety operations can declare as volatile types to avoid data race checking.
Build this project with following commands:
$ make # Generate static library: libucsan.a
$ make clean # Delete generated files
nr_cpu
: number of cpu.nr_wp
: number of watchpoint slot.CC
: compiler, gcc or clang.
Add the static library libucsan.a
to your project:
$ gcc -c main.c -fsanitize=thread
$ gcc -o main main.o -L/path/to/libucsan/ -lucsan -rdynamic -pthread
Or you can move the libucsan.a
to your project directory. Then:
$ gcc -c main.c -fsanitize=thread
$ gcc -o main main.o libucsan.a -rdynamic -pthread