Zum Inhalt springen
L

Das Video kommt von YouTube: erst beim Abspielen verbindet sich die Seite mit YouTube (Google).

Everything you should know about deadlock in three minutes or less

Chris Kanich2:50 23.773 Aufrufe veröffentlicht Auf YouTube

Das Wichtigste aus dem Video

Tipp auf eine Zeit – das Video springt genau dorthin.

Transkriptautomatisch erstellt · 25 Zeilen
Herunterladen
  1. this video is about deadlock deadlock is when a program can't make any forward progress due to broken locking this is about the easiest code
  2. you can write that causes a deadlock in this code we're going to run two threads a jack thread and a jail thread
  3. the jack thread locks x and then it lacks y and then it prints something it unlocks and it starts that process over again
  4. jill locks y then locks x prints something and then releases both locks and repeats that if we run this program we'll see
  5. very quickly that it ends up in deadlock ta-da immediately goes into deadlock didn't get to print a single time let's try it
  6. one more time now here we see that it printed jack a whole bunch of times but right now there's nothing else happening on the screen we can take a
  7. closer look at this by running it in the debugger here we see that we get started and we can continue from the pause on entry it runs
  8. and then at this point in time i can manipulate this code nothing is happening now that we've paused these threads
  9. let's take a look at where they're stuck the jack thread is attempting to gain access to the y mutex because it's on this line
  10. that means it already got access to the x mutex the jail thread has access to the y mutex and is waiting to gain access to the x mutex
  11. neither of these threads will ever finish all three of these threads are blocked waiting for something else to happen which will never happen
  12. one helpful way to think about deadlock is that it's a situation that requires four conditions to actually happen condition one is that
  13. you're using mutual exclusion locks such that only one thread can hold a resource at one time condition two is that each of these
  14. threads gains access to their resources one at a time holds on to them and waits until they gain access to the next one condition three is that a thread cannot
  15. be preempted that is it can't have its access to a lock revoked by another thread besides itself without
  16. voluntarily deciding to give up that lock condition 4 is probably the most important in condition 4 what you need is a circular weight what
  17. this means is that jack is waiting for jill to give up a resource and at the same time jill is waiting for
  18. jack to give up a resource in this example there are two threads waiting on each other but any cycle between multiple threads would still
  19. cause deadlock we can also see an example of deadlock in our train simulator as we see here there are two areas
  20. protected by the train signals that act as mutual exclusion locks if i start both of these trains they will start moving but then eventually
  21. they're going to end up in a deadlock situation as we see here one train is waiting for the other to leave that lock
  22. but because it's so long it will hold on to that lock for quite some time now we see the deadlock one train is holding the lock
  23. that the other one needs while that one is holding the lock that the first one needs this is a circular weight that can't be revoked
  24. besides by deleting the train one of them is holding the lock and they're waiting until they get access to the next lock and is using
  25. multiple locks this satisfies all four of our deadlock conditions this has been cs361 have a good one

Zum Nachlesen