07.01.2013 Views

Lecture Notes in Computer Science 3472

Lecture Notes in Computer Science 3472

Lecture Notes in Computer Science 3472

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

532 Séver<strong>in</strong>e Col<strong>in</strong> and Leonardo Mariani<br />

occur <strong>in</strong> the exam<strong>in</strong>ed execution trace. The goal is to extract as much <strong>in</strong>formation<br />

as possible from a s<strong>in</strong>gle execution trace to be able to forecast problems that can<br />

occur <strong>in</strong> executions that have not been explored. In the case of multi-threaded<br />

software, debugg<strong>in</strong>g is complex s<strong>in</strong>ce execution of threads is not determ<strong>in</strong>istic<br />

and many comb<strong>in</strong>ations are possible, thus verification requires specific tools. In<br />

this section, we present the application of run-time verification techniques for<br />

detect<strong>in</strong>g data races and deadlocks.<br />

18.4.1 Data Races<br />

The Eraser algorithm [SBN + 97] is one of the first algorithms that dynamically<br />

detects data races <strong>in</strong> multi-threaded programs. A date race occurs when two<br />

concurrent threads access a shared variable with at least one write access and<br />

threads use no explicit mechanism to prevent accesses from be<strong>in</strong>g simultaneous.<br />

The Eraser algorithm takes an unmodified program b<strong>in</strong>ary as <strong>in</strong>put and<br />

adds <strong>in</strong>strumentation to produce a new b<strong>in</strong>ary that is functionally identical, but<br />

<strong>in</strong>cludes calls to the Eraser run-time which implements the Lockset algorithm.<br />

The Lockset algorithm enforces the lock<strong>in</strong>g discipl<strong>in</strong>e requir<strong>in</strong>g that every<br />

variable shared between threads is protected by a mutual exclusion lock. As a<br />

consequence, the lock must be held by threads access<strong>in</strong>g the variable. Basically,<br />

Eraser <strong>in</strong>struments standard C, C++ and Unix memory allocation rout<strong>in</strong>es and<br />

monitors all read and write operations to check whether the program respects<br />

or not the lock<strong>in</strong>g policy. Eraser does not know which locks are <strong>in</strong>tended to protect<br />

which variables, so it must <strong>in</strong>fer the protection relation from the execution<br />

history.<br />

In particular, for each shared variable v, Eraser ma<strong>in</strong>ta<strong>in</strong>s the set C (v) of<br />

candidate locks for v. This set conta<strong>in</strong>s those locks that have protected v for<br />

the computation so far, that is, a lock l is <strong>in</strong> C (v) if <strong>in</strong> the current computation<br />

every thread that has accessed v was hold<strong>in</strong>g l at the moment of the access.<br />

When a new variable v is <strong>in</strong>itialized, its candidate set C (v) is considered to hold<br />

all possible locks. When the variable is accessed, Eraser updates C (v) withthe<br />

<strong>in</strong>tersection of C (v) and the set of locks held by the current thread. This process,<br />

called lockset ref<strong>in</strong>ement, ensures that anylockthatconsistentlyprotectsv is<br />

conta<strong>in</strong>ed <strong>in</strong> C (v). If C (v) becomes empty, no locks consistently protect v.<br />

A lock is a simple synchronization object used to implement mutual exclusion.<br />

Locks can be either available or owned by a thread. The operations that can be<br />

performed on a lock mu are lock(mu) andunlock(mu). Figure 18.3 shows an<br />

example taken from the paper present<strong>in</strong>g the Eraser algorithm [SBN + 97] that<br />

illustrates how a potential data race is discovered through lockset ref<strong>in</strong>ement.<br />

The left column conta<strong>in</strong>s the program statements that are executed;the column<br />

<strong>in</strong> the middle conta<strong>in</strong>s the set of locks held by the considered thread; and the<br />

right column conta<strong>in</strong>s the set of candidate locks C (v). The example uses two<br />

locks mu1 and mu2, thusC (v) <strong>in</strong>itially conta<strong>in</strong>s both of them. Then, the lock<br />

mu1 is acquired and v is accessed. Thus, C (v) is ref<strong>in</strong>ed by comput<strong>in</strong>g the<br />

<strong>in</strong>tersection of C (v) with the set of acquired locks. Later, v is accessed aga<strong>in</strong>,<br />

when only mu2 is held. The <strong>in</strong>tersection of the s<strong>in</strong>gleton {mu1} with {mu2} is

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!