Deadlock and Starvation in C#


Deadlock occurs when a resource is locked by a thread and is required by another thread at the same time. This problem occur frequenty in a multiprocessing system.

It can occur when two or more threads wait for a resource that belon to another thread. Here is an example −

Thread One Thread Two
Takes Lock P Takes Lock Q
Requests Lock Q Requests Lock P

Thread One will not get Lock Q since it belongs to Thread Two. In the same way, Thread Two won’t get Lock P since its original owner is Thread One.

Deadlocks can also be a three-way deadlock that occurs if three threads and three locks are common. In the same way, it can occur for four-way, five-way, and other deadlocks.

Starvation is permanent blocking of one or more runnable threads in a multithreaded application.

raja
Published on 21-Aug-2018 14:01:28
Advertisements