DRD: a thread error detector
2. Synchronization operations determine certain ordering constraints on memory operations performed by different
threads. These ordering constraints are called the
synchronization order
.
The combination of program order and synchronization order is called the
happens-before relationship
. This concept
was first defined by S. Adve et al in the paper
Detecting data races on weak memory systems
, ACM SIGARCH
Computer Architecture News, v.19 n.3, p.234-243, May 1991.
Two memory operations
conflict
if both operations are performed by different threads, refer to the same memory
location and at least one of them is a store operation.
A multithreaded program is
data-race free
if all conflicting memory accesses are ordered by synchronization
operations.
A well known way to ensure that a multithreaded program is data-race free is to ensure that a locking discipline is
followed. It is e.g. possible to associate a mutex with each shared data item, and to hold a lock on the associated mutex
while the shared data is accessed.
All programs that follow a locking discipline are data-race free, but not all data-race free programs follow a locking
discipline. There exist multithreaded programs where access to shared data is arbitrated via condition variables,
semaphores or barriers. As an example, a certain class of HPC applications consists of a sequence of computation
steps separated in time by barriers, and where these barriers are the only means of synchronization. Although there
are many conflicting memory accesses in such applications and although such applications do not make use mutexes,
most of these applications do not contain data races.
There exist two different approaches for verifying the correctness of multithreaded programs at runtime. The approach
of the so-called Eraser algorithm is to verify whether all shared memory accesses follow a consistent locking strategy.
And the happens-before data race detectors verify directly whether all interthread memory accesses are ordered by
synchronization operations. While the last approach is more complex to implement, and while it is more sensitive to
OS scheduling, it is a general approach that works for all classes of multithreaded programs. An important advantage
of happens-before data race detectors is that these do not report any false positives.
DRD is based on the happens-before algorithm.
8.2. Using DRD
8.2.1. DRD Command-line Options
The following command-line options are available for controlling the behavior of the DRD tool itself:
--check-stack-var=<yes|no> [default:
no]
Controls whether DRD detects data races on stack variables. Verifying stack variables is disabled by default because
most programs do not share stack variables over threads.
--exclusive-threshold=<n> [default:
off]
Print an error message if any mutex or writer lock has been held longer than the time specified in milliseconds. This
option enables the detection of lock contention.
--join-list-vol=<n> [default:
10]
Data races that occur between a statement at the end of one thread and another thread can be missed if memory access
information is discarded immediately after a thread has been joined. This option allows to specify for how many joined
threads memory access information should be retained.
123