
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements