1 / 16

Today’s Agenda

Today’s Agenda. HW #2 Out Replay Semaphore and Lock Advanced Locking. Tracing/Replay for Semaphores and Locks. PV-sequence & Lock/Unlock-sequence Trace and Replay. Shared Objects. Let P be a concurrent program that uses shared variables , semaphores and locks .

bjorn
Download Presentation

Today’s Agenda

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. Today’s Agenda • HW #2 Out • Replay Semaphore and Lock • Advanced Locking Advanced Topics in Software Engineering 1

  2. Tracing/Replay for Semaphores and Locks • PV-sequence & Lock/Unlock-sequence • Trace and Replay Advanced Topics in Software Engineering 2

  3. Shared Objects • Let P be a concurrent program that uses shared variables, semaphores and locks. • The outcome of executing P with a given input depends on the order in which shared objects in P are accessed. • P’s shared objects are its shared variables, semaphores, and locks. Advanced Topics in Software Engineering 3

  4. PV-sequence • A SYN-sequence for a semaphore is referred to as a PV-sequence, which consists of a sequence of events of the following types: • completion of a P operation • completion of a V operation • start of a P operation that is never completed • start of a V operation that is never completed Advanced Topics in Software Engineering 4

  5. PV-sequence (cont’d) • An event in a PV-sequence is encoded by the identifier (ID) of the thread that executes the P or V operation. • The order in which threads complete P and V operations is not necessarily the same as the order in which these P and V operations start. Advanced Topics in Software Engineering 5

  6. PV-sequence (cont’d) Let s be a binary semaphore initialized with 0. Thread 1 ... s.P(); ... s.V(); ... s.V(); ... s.V() ... Thread 2 ... s.V(); ... s.P(); ... s.P(); ... s.V() ... 2, 1, 1, 2, 1, 2, 1, 2 Advanced Topics in Software Engineering 6

  7. Lock/Unlock-sequence • A SYN-sequence for a lock is referred to as a Lock/Unlock-sequence, which consists of a sequence of events of the following types: • completion of a lock operation • completion of a unlock operation • start of a lock operation that is never completed • start of a unlock operation that is never completed Advanced Topics in Software Engineering 7

  8. Lock/Unlock-sequence (cont’d) • An event in a Lock/Unlock-sequence is encoded by the identified (ID) of the thread that executed the Lock or Unlock operation. • The order in which threads complete Lock and Unlock operations is not necessarily the same as the order in which these Lock and Unlock operations start. Advanced Topics in Software Engineering 8

  9. Lock/Unlock-sequence (cont’d) Let l be a mutex lock. Thread 1 ... l.lock(); (1) x = 1; (2) l.unlock(); (3) ... Thread 2 ... l.lock(); (1) x = 2; (2) l.unlock(); (3) ... 1, 1, 2, 2 Advanced Topics in Software Engineering 9

  10. SYN-sequence for a program • A SYN-sequence for a concurrent program is a collection of RW-sequence, PV-sequence, and Lock/Unlock-sequence, where there is one sequence for each sharedvariable, semaphore, and lock in the program. Advanced Topics in Software Engineering 10

  11. Replay • Assume that shared variables are always safely accessed within critical sections. • If we replay PV-sequence or Lock/Unlock-sequence, then the RW-sequence of each shared variable will be replayed. Advanced Topics in Software Engineering 11

  12. P & V methods • P() { • if (replay) { • control.requestPermit (ID); • } • // enter the CS • if (replay) { • control.releasePermit(); • } • /* body of P () */ • if (trace) { • control.traceCompleteP (ID); • } • // leaving the CS • } V() { if (replay) { control.requestPermit(ID); } // enter the CS if (replay) { control.releasePermit(); } /* body of P () */ if (trace) { control.traceCompleteV (ID); } // leave the CS } Advanced Topics in Software Engineering 12

  13. Lock & Unlock methods • Lock & Unlock methods for a mutex lock will be implemented in a way that is similar to P & V methods. Advanced Topics in Software Engineering 13

  14. class control • Each semaphore or lock is associated with a control object. • In trace mode, the control object collects and records the sequence of synchronization events. • In replay mode, the control object inputs the SYN-sequence of the semaphore or mutex lock and handles the calls to requestPermit and releasePermit. Advanced Topics in Software Engineering 14

  15. class control (cont’d) • public class control { • privateVector SYNsequence; // PV-sequence or Lock/Unlock-sequence; sequence of IDs • privateBinarySemaphore [] threads; // all semaphores initialized to 0 • boolean [] hasRequested; // hasRequested[i] is true if Ti is delayed in requestPermit • int index = 0; // index into SYNsequence • MutexLock mutex; • public control () { • // initialization • } • publicvoid requestPermit (int ID) { • mutex.lock (); • if (ID != SYNsequence[index]) { • hasRequested[ID] = true; • mutex.unlock (); • threads[ID].P (); • hasRequested[ID] = false; • } • else mutex.unlock (); • } • publicvoid releasePermit () { • mutex.lock (); • ++ index; • if (index < SYNSequence.size ()) { • if (hasRequested[SYNsequence[index]]) { threads[SYNsequence[index]].V(); • } • } • mutex.unlock (); • } • publicvoid traceCompleteP (int ID) { ... } // record integer ID • publicvoid traceCompleteV (int ID) { ... } // record integer ID • } Advanced Topics in Software Engineering 15

  16. Example Consider the example lock/unlock sequence discussed earlier. What happens if T2 attempts the lock operation first during replay? T1 T2 (1) ID != SYNSequence[0] hasRequested[2] = true; (1) (2) (3) ID == SYNSequence[0] ID == SYNSequence[1] (1) (2) (3) ID == SYNSequence[2] ID == SYNSequence[3] 1, 1, 2, 2 Advanced Topics in Software Engineering 16

More Related