Both the threads T1 and T2 won’t set free their respective resources R1 and R2 until they finish the execution of the thread. ![]() Now thread T1 is requesting the resource R2, and T2 is requesting the resource R1. Have you ever wondered how deadlock occurs in local machines? Let us see an example to understand deadlock in computer systems.Ĭonsider two threads, T1 and T2, and both have locked/occupied the resources, R1 and R2, respectively. Both vehicles would have to wait indefinitely to cross the bridge. So this is considered to be a deadlock situation. ![]() To clear the path for V1, V2 has to go back or else vice versa, but both vehicles can't go back. In the above situation, neither V1 nor V2 can cross the bridge as both vehicles block the bridge for each other. Two vehicles, V1 and V2, are crossing the bridge at the same time but from opposite ends of the bridge, as shown in the figure below.Ĭonsider that both the vehicles don’t have a reverse gear. Imagine a narrow bridge where only a single vehicle can pass at a time. Let us understand deadlock in a real-world scenario. Hence, both threads are waiting for each other to release the lock, creating a deadlock situation. ![]() For example, a deadlock can occur in a situation when a thread is waiting to acquire an object's lock that is acquired by another thread, and the second thread is waiting to acquire another object's lock that is acquired by the first thread. Deadlock situation takes place mainly in Multithreaded programming. Deadlock in Java is a situation where two or more processes are waiting indefinitely for one another's action.
0 Comments
Leave a Reply. |