
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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.
- Related Articles
- Starvation and Deadlock
- Difference Between Deadlock and Starvation in OS
- Deadlock Characterization
- Deadlock in Java Multithreading
- Error codes, cause and example of deadlock in DB2
- Deadlock with mutex locks
- Display all deadlock logs in MySQL?
- Investigation of root cause and resource responsible for the deadlock in DB2
- How can we avoid a deadlock in Java?
- C++ Program for Deadlock free condition in Operating Systems
- What are the types of process scheduling algorithms and which algorithms lead to starvation?
- The excessive use of one of the following in agriculture can cause the death of fish in a pond by oxygen starvation. This one is:fertilizersmanurespesticidesherbicides
- Bitwise AND and OR in Arduino
- Logical AND and OR in Arduino
- What is different in & and AND operators in Python?

Advertisements