1 / 33

Rahul Agarwal and Scott D. Stoller PADTAD 2006 Kim, Byung-Chul Operating System Lab in GNU

Run-Time Detection of Potential Deadlocks for Programs with Locks, Semaphores, and Condition Variables. Rahul Agarwal and Scott D. Stoller PADTAD 2006 Kim, Byung-Chul Operating System Lab in GNU. Abstract. Deadlock A common kind of concurrency errors in concurrent programs

akiko
Download Presentation

Rahul Agarwal and Scott D. Stoller PADTAD 2006 Kim, Byung-Chul Operating System Lab in GNU

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Run-Time Detection of Potential Deadlocks for Programs with Locks, Semaphores, and Condition Variables RahulAgarwal and Scott D. Stoller PADTAD 2006 Kim, Byung-Chul Operating System Lab in GNU

  2. AgSt06 Abstract • Deadlock • A common kind of concurrency errors in concurrent programs • occurs when some threads are permanently blocked • difficult to reproduce and diagnose • Previous work on run-time detection of potential deadlocks • for only programs with locks. • This paper • defines a run-time notion of potential deadlock in such programs with locks, semaphores, and condition variables • presents run-time algorithms to detect potential deadlocks in programs with locks, semaphores, and condition variables

  3. AgSt06 Synchronization Mechanisms • Locks • lock acquire, and lock release operations • Semaphores • up, and down operations • Condition variables • wait, and notity/notifyAll operations • Fork and join • start and join operations

  4. AgSt06 Blocking Event • An event is one step in the execution of a program • Synchronization events and access events to shared variables • A trace is a sequence of events in a given program • A event e is called a blocking event if one of the following holds • e is an acquire of a lock l by thread t, and l is currently held by another thread when e occurs • e is a wait on a condition variable • e is a down on a semaphore whose value is 0

  5. AgSt06 Deadlock Blocking events t1 t2 t3 T = {T2, T3} A trace tr deadlocks if a set T of threads in tr exists, such that the last event for each thread in T is a blocking event, and all threads in tr not in T have terminated

  6. AgSt06 Feasible Permutation of a Trace • A feasible permutation of a trace is a trace that is • Consistent with the origin order of events from each thread • Consistent with the constraints imposed by synchronizations • Constraints by locks: no lock is held by multiple threads at the same time • Constraints by others: happens-before orderings

  7. AgSt06 Happens-Before Ordering t2.start t1 t1 t2 t2 t1.join • Happens-before is a partial order on the events in an execution. • If event e1 happens-before event e2, then e1 must occur before e2 in all feasible permutations of the trace • Happens-before orderings due to start/join operations

  8. AgSt06 Potential for Deadlock • A trace has potential for deadlock, if some feasible permutation of the trace deadlocks • This definition considers all synchronization mechanisms together

  9. AgSt06 Potential for Deadlock due to Locks • A trace has potential for deadlock due to locks if some feasible permutation of the trace restricted to operations on locks and operations on threads deadlocks. • A simpler condition can be checked more efficiently but produce false alarms • Ignoring the effect of gate locks and thread synchronizations • A program has potential for deadlock due to locks ignoring gate locks (PDL-IGL) if there exist distinct threads t0,…,tm-1 and locks l0,…,lm-1 in the given trace tr such that, for all i = 0,…,m-1, ti holds lock li while acquiring lock li+1 mod m.

  10. AgSt06 acquire (l4); T4 acquire (l3); acquire (l1); l4 l3 release (l4); release (l1); l3 l1 l1 release (l3); • Run-time lock trees • keeps track of which locks are held by a thread when it acquires another lock.

  11. AgSt06 T1 T4 l1 l3 l4 l3 l2 l4 l3 l1 • Run-time lock graph G = (V, E) • V: all the nodes of all the run-time lock trees • E: tree edges or inter edges between two distinct nodes • tree edges: directed edges in each of the run-time lock trees • inter edges: bidirectional edges between nodes that are labeled with the same lock and that are in different run-time lock trees.

  12. AgSt06 • PDL-IGL holds iif the run-time lock graph G contains a valid cycle • A valid cycle is a cycle • that does not contain consecutive inter edges and • such that nodes from each thread appear as at most one consecutive subsequence in the cycle

  13. AgSt06 Example of a Lock Graph T1 T1 T3 T4 l1 l3 l2 l4 l4 l3 l2 l4 l3 l1 l3 l1 l1

  14. AgSt06 Non-Valid Cycle T1 T1 T3 T4 l1 l3 l2 l4 l4 l3 l2 l4 l3 l1 l3 l1 l1

  15. AgSt06 Non-Valid Cycle T1 T1 T3 T4 l1 l3 l2 l4 l4 l3 l2 l4 l3 l1 l3 l1 l1

  16. AgSt06 Valid Cycles T1 T1 T3 T4 l1 l3 l2 l4 l4 l3 l2 l4 l3 l1 l3 l1 l1

  17. AgSt06 lg lg l0 l1 l0 l1 l1 l0 l1 l0 deadlock no deadlock Gate Lock

  18. AgSt06 Potential for Deadlocks with Locks (PDL) • A program has potential for deadlocks with locks if there exists distinct t0,…,tm-1 and lock l0,…,lm-1 such that for all i=0,…,m-1, ti holds lock li while acquiring lock li+1mod m and there not do not exist ti, tj, and l such that ti and tj hold l when acquiring li and lj, respectively. • The algorithm of PDL-IGL is extended for PLD • Each thread maintains for each edge (l, l’), a set of locks that were held but not released at the time the thread acquired lock l’ while also holding lock l. • After detecting a valid cycle, check if two edges in the cycle share a common lock.

  19. AgSt06 lock graph for PDL-IGL lock graph for PDL T0 T1 T0 T1 lg l0 lg l1 lg l0 lg l1 lg,l0 lg,l1 l0 l1 l1 l0 l0 l1 l1 l0

  20. AgSt06 Detection of Potential for Deadlock due to Semaphores • Potential for deadlocks due to semaphores • An execution trace has potential for deadlocks due to semaphores if some feasible permutation of the trace restricted to operations on semaphores and operations on threads deadlocks. • Two nature of semaphores • Mutual exclusion: analyzed exactly as if they were locks, with down treated as acquire, and up treated as release • Condition synchronization: analyzed with all feasible permutations allowed by the ordering constraints, tracking the values of the semaphore

  21. AgSt06 Happens-Before Ordering due to Semaphore for Condition Synchronization o t1 o m t2 o down operation on semaphore o o up operation on semaphore o • An up event eu that unblocks a thread blocked on a down event ed happens-before succ(ed), where succ(e) is the event immediately following e on the same thread.

  22. AgSt06 Deadlock-free trace t p o init values o = 1; t = 0; p = 0; m = 0; p m o t1 o p m o t p t2 t3 t down operation on semaphore t t up operation on semaphore t

  23. AgSt06 Happens-Before Ordering for the Trace t p o p m o t1 t2 o p m o t p t3

  24. AgSt06 Feasible Permutation with Deadlock init values o = 1; t = 0; p = 0; m = 0; t p p m t1 t2 o o t p t3

  25. AgSt06 Detection of Potential for Lost Notifies • Potential for lost notify • An execution trace tr has potential for lost notify if it contains a notify or notifyall event e such that there is a feasible permutation of tr in which e wakes up fewer threads than it does in tr.

  26. AgSt06 Happens-Before Ordering due to Lost Notifies acquire wait release acquire • For each notify or notifyAll event en and each wait event ew that is notified by en, en happens-before succ(ew), where succ(e) is the event immediately after e on the same thread. • Since, the same lock l must be held when ew and en occur and only one thread can hold a given lock at a time, this is equivalent to saying that the release of l after en happens-before succ(ew). acquire notify release

  27. AgSt06 Trace without Lost Notify acquire wait release acquire acquire notify release

  28. AgSt06 Happens-Before Ordering for the Trace acquire wait release acquire acquire notify release

  29. AgSt06 Feasible Permutation with Lost Notify acquire wait release acquire acquire notify release

  30. AgSt06 Detection of Potential Deadlocks due to Locks, Condition Variables, and Semaphores acq(a) acq(b) rel(b) acq(b) t1 wait notify t2 s acq(b) rel(b) t3 s acq (a) rel (a) Trace without deadlocks

  31. AgSt06 acq(a) acq(b) rel(b) acq(b) t1 wait notify t2 s acq(b) rel(b) t3 s acq (a) rel (a) Happens-before ordering for the trace

  32. AgSt06 acq(a) acq(b) t1 wait t2 s t3 acq (a) Feasible permutation with deadlock

  33. AgSt06 acq(a) acq(b) rel(b) acq(b) t1 wait notify t2 s acq(b) rel(b) t3 s acq (a) rel (a) Feasible permutation with lost notifies

More Related