DRD: a thread error detector
• A shared address space. All threads running within the same process share the same address space. All data, whether
shared or not, is identified by its address.
• Regular load and store operations, which allow to read values from or to write values to the memory shared by all
threads running in the same process.
• Atomic store and load-modify-store operations. While these are not mentioned in the POSIX threads standard, most
microprocessors support atomic memory operations.
• Threads. Each thread represents a concurrent activity.
• Synchronization objects and operations on these synchronization objects. The following types of synchronization
objects have been defined in the POSIX threads standard: mutexes, condition variables, semaphores, reader-writer
synchronization objects, barriers and spinlocks.
Which source code statements generate which memory accesses depends on the
memory model
of the programming
language being used. There is not yet a definitive memory model for the C and C++ languages. For a draft memory
model, see also the document WG21/N2338: Concurrency memory model compiler consequences.
For more information about POSIX threads, see also the Single UNIX Specification version 3, also known as IEEE
Std 1003.1.
8.1.3. Multithreaded Programming Problems
Depending on which multithreading paradigm is being used in a program, one or more of the following problems can
occur:
• Data races. One or more threads access the same memory location without sufficient locking. Most but not all data
races are programming errors and are the cause of subtle and hard-to-find bugs.
• Lock contention. One thread blocks the progress of one or more other threads by holding a lock too long.
• Improper use of the POSIX threads API. Most implementations of the POSIX threads API have been optimized for
runtime speed. Such implementations will not complain on certain errors, e.g. when a mutex is being unlocked by
another thread than the thread that obtained a lock on the mutex.
• Deadlock. A deadlock occurs when two or more threads wait for each other indefinitely.
• False sharing. If threads that run on different processor cores access different variables located in the same cache
line frequently, this will slow down the involved threads a lot due to frequent exchange of cache lines.
Although the likelihood of the occurrence of data races can be reduced through a disciplined programming style, a tool
for automatic detection of data races is a necessity when developing multithreaded software. DRD can detect these, as
well as lock contention and improper use of the POSIX threads API.
8.1.4. Data Race Detection
The result of load and store operations performed by a multithreaded program depends on the order in which memory
operations are performed. This order is determined by:
1. All memory operations performed by the same thread are performed in
program order
, that is, the order determined
by the program source code and the results of previous load operations.
122