Home

ThreadSanitizer

ThreadSanitizer, commonly abbreviated as TSan, is a dynamic data race detector for multithreaded native programs. It is part of the LLVM Sanitizers family and is widely used to identify concurrency errors in C, C++, and other languages that compile with LLVM-based toolchains.

TSan operates by instrumenting code at compile time to monitor memory accesses and synchronization operations. It

Usage and availability: To use it, compile with -fsanitize=thread (and -g for debugging information). Run the

Limitations: The instrumentation introduces substantial runtime overhead and memory usage, which can slow execution and alter

maintains
metadata
about
memory
locations
and
the
happens-before
relationships
between
actions
performed
by
different
threads,
typically
using
shadow
memory
and
vector
clocks.
When
two
or
more
threads
access
the
same
memory
location
concurrently,
and
at
least
one
access
is
a
write
without
proper
synchronization,
TSan
reports
a
data
race.
Reports
include
the
location
in
source
code,
stack
traces,
participating
threads,
and
the
nature
of
the
conflicting
access.
program
normally;
a
detected
race
is
reported
on
standard
error
with
a
stack
trace.
TSan
is
supported
with
the
Clang/LLVM
toolchain
on
major
platforms
such
as
Linux
and
macOS,
and
is
available
in
compatible
toolchains
on
Windows.
It
can
detect
races
in
C
and
C++,
and
in
other
languages
that
can
be
built
with
LLVM-based
compilers,
including
Rust
in
typical
LLVM
workflows.
timing
in
multithreaded
programs.
It
may
not
report
races
in
code
that
runs
in
non-instrumented
libraries
or
in
certain
intricate
synchronization
patterns,
and
false
positives
or
negatives
can
occur
in
edge
cases.