1 / 31

Deadlock

Deadlock. 4 necessary conditions Mutual exclusion Hold and wait No preemption Circular wait. Figure 6.7 Deadlock example. Threads T1 and T2 hold locks L1 and L2, respectively, and each thread attempts to acquire the other lock, which cannot be granted. Preventing Deadlock.

tlerma
Télécharger la présentation

Deadlock

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. Deadlock • 4 necessary conditions • Mutual exclusion • Hold and wait • No preemption • Circular wait

  2. Figure 6.7 Deadlock example. Threads T1 and T2 hold locks L1 and L2, respectively, and each thread attempts to acquire the other lock, which cannot be granted.

  3. Preventing Deadlock • Two major categories for dealing with deadlock • Prevent deadlock from happening • Detect deadlocks and then break the deadlock

  4. Lock Hierarchies – preventing deadlock Each lock is assigned a position in an ordering. Must acquire the locks in order Assumes a priori knowledge of all the locks needed. If need a lower lock after acquiring a higher lock, could release the higher locks, acquire the lower locks and then reacquire the higher locks.

  5. Monitors Abstract concept that could be implemented in a language. Only allows one thread access to the data. Has one single entry point for several methods

  6. Figure 6.8 Monitors provide an abstraction of synchronization in which only one thread can access the monitor’s data at any time. Other threads are blocked either waiting to enter the monitor or waiting on events inside the monitor.

  7. Figure 6.12 Multiple readers, single writer support routines.

  8. Figure 6.13 Multiple readers, single-writer support routines based on a single-conditionvariable, but subject to spurious wake-ups.

  9. Thread Scheduling • Two ways to have a thread • Map multiple threads to a single OS aware thread • Unbound threads • Create and destroy overhead low • If OS blocks this thread, all the mapped threads are blocked also • Map each thread to its own OS aware thread • Bound threads • Better performance expected

  10. Code Spec 6.18 POSIX Thread routine for setting thread scheduling attributes.

  11. Figure 6.14 A 2D relaxation replaces—on each iteration—all interior values by the average of their four nearest neighbors.

  12. Figure 6.15 False Sharing – when a processor has more from the shared memory in its cache than is “allocated” to that processor

  13. Figure 6.16 2D Sucessive over-relaxation program written using POSIX Threads.

  14. Figure 6.16 2D Sucessive over-relaxation program written using POSIX Threads. (cont.)

  15. Figure 6.16 2D Sucessive over-relaxation program written using POSIX Threads. (cont.)

  16. Figure 6.16 2D Sucessive over-relaxation program written using POSIX Threads. (cont.) 0 1

  17. Figure 6.17 It’s often profitable to do useful work while waiting for some long-latency operation to complete.

  18. Figure 6.18 A split-phase barrier allows a thread to do useful work while waiting for the other threads to arrive at the barrier.

  19. Figure 6.19 A 1D over-relaxation replaces—on each iteration—all interior values by the average of their two nearest neighbors.

  20. Figure 6.20 Program for 1D successive over-relaxation using a single-phase barrier. +1

  21. Figure 6.21 Program for 1D successive over-relaxation using a split-phase barrier. +1

  22. Figure 6.21 Program for 1D successive over-relaxation using a split-phase barrier. (cont.)

  23. Code Spec 6.19 Java’s Thread class methods.

  24. Figure 6.27 Count 3s solution in Java.

  25. Figure 6.27 Count 3s solution in Java. (cont.)

  26. Figure 6.27 Count 3s solution in Java. (cont.)

  27. Code Spec 6.20 Examples of Java’s atomic objects.

  28. Figure 6.28 OpenMP schedule (static)

  29. Code Spec 6.21 OpenMP parallel for statement.

  30. Code Spec 6.22 OpenMP reduce operation. The <op> choice comes from the accompanying table.

  31. Code Spec 6.23 Atomic specification in OpenMP.

More Related