Skip Navigation Links | |
Exit Print View | |
![]() |
Oracle Solaris Studio 12.3: Thread Analyzer User's Guide Oracle Solaris Studio 12.3 Information Library |
1. What is the Thread Analyzer and What Does It Do?
3.2 Getting the Deadlock Tutorial Source Files
3.2.1 Source Code Listing for din_philo.c
3.3 The Dining Philosophers Scenario
3.3.1 How the Philosophers Can Deadlock
3.3.2 Introducing a Sleep Time for Philosopher 1
3.4 How to Use the Thread Analyzer to Find Deadlocks
3.4.2 Create a Deadlock Detection Experiment
3.4.3 Examine the Deadlock Detection Experiment
3.4.3.1 Using Thread Analyzer to View the Deadlock Detection Experiment
3.4.3.2 Using er_print to View the Deadlock Detection Experiment
3.5 Understanding the Deadlock Experiment Results
3.5.1 Examining Runs That Deadlock
3.5.2 Examining Runs That Complete Despite Deadlock Potential
3.6 Fixing the Deadlocks and Understanding False Positives
3.6.1 Regulating the Philosophers With Tokens
3.6.1.1 A False Positive Report
3.6.2 An Alternative System of Tokens
The term deadlock describes a condition in which two or more threads are blocked forever because they are waiting for each other. There are many causes of deadlocks such as erroneous program logic and inappropriate use of synchronizations such as locks and barriers. This tutorial focuses on deadlocks that are caused by the inappropriate use of mutexes, or mutual exclusion locks. This type of deadlock is commonly encountered in multithreaded applications.
A process with two or more threads can enter deadlock when the following three conditions hold:
Threads that are already holding locks request new locks
The requests for new locks are made concurrently
Two or more threads form a circular chain in which each thread waits for a lock which is held by the next thread in the chain
Here is a simple example of a deadlock condition:
Thread 1 holds lock A and requests lock B
Thread 2 holds lock B and requests lock A
A deadlock can be of two types: A potential deadlock or an actual deadlock and they are distinguished as follows:
A potential deadlock does not necessarily occur in a given run, but can occur in any execution of the program depending on the scheduling of threads and the timing of lock requests by the threads.
An actual deadlock is one that occurs during the execution of a program. An actual deadlock causes the threads involved to hang, but may or may not cause the whole process to hang.