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
Das Wichtigste aus dem Video
Tipp auf eine Zeit – das Video springt genau dorthin.
Transkriptautomatisch erstellt · 25 Zeilen
- 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
- you can write that causes a deadlock in this code we're going to run two threads a jack thread and a jail thread
- the jack thread locks x and then it lacks y and then it prints something it unlocks and it starts that process over again
- jill locks y then locks x prints something and then releases both locks and repeats that if we run this program we'll see
- 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
- 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
- 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
- and then at this point in time i can manipulate this code nothing is happening now that we've paused these threads
- 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
- 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
- neither of these threads will ever finish all three of these threads are blocked waiting for something else to happen which will never happen
- one helpful way to think about deadlock is that it's a situation that requires four conditions to actually happen condition one is that
- 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
- 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
- be preempted that is it can't have its access to a lock revoked by another thread besides itself without
- 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
- this means is that jack is waiting for jill to give up a resource and at the same time jill is waiting for
- 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
- cause deadlock we can also see an example of deadlock in our train simulator as we see here there are two areas
- 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
- 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
- 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
- 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
- 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
- multiple locks this satisfies all four of our deadlock conditions this has been cs361 have a good one
Zum Nachlesen
Deadlock (Informatik)Deadlock oder Verklemmung bezeichnet in der Informatik einen Zustand, bei dem eine zyklische Wartesituation zwischen mehreren Prozessen auftritt, …
DeadlockEin Deadlock in der Informatik bezeichnet eine ausweglose Situation, bei dem sich mehrere Prozesse blockieren, weil sie gegenseitig aufeinander warten. Ein …
ProzesssynchronisationGemeinsamer Zugriff auf Daten. Dabei muss verhindert werden, dass durch gleichzeitigen Zugriff Inkonsistenzen in den Daten entstehen. Dies wird durch Mutex- …
SpinlockEs ist eine Sperre (Lock) zum Schutz einer gemeinsam genutzten Ressource durch konkurrierende Prozesse bzw. Threads (siehe Kritischer Abschnitt) nach dem …