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 OneThread Two
Takes Lock PTakes Lock Q
Requests Lock QRequests 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.

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements