Oracle® Solaris Studio 12.4: Thread Analyzer User's Guide

Exit Print View

Updated: December 2014
 
 

Examining Runs That Complete Despite Deadlock Potential

The dining philosophers program can avoid actual deadlock and terminate normally if you supply a large enough sleep argument. Normal termination, however, does not mean the program is safe from deadlocks. It simply means that the locks that were held and requested did not form a deadlock chain during a given run. If the timing changes in other runs, an actual deadlock can occur. The following listing shows a run of the dining philosophers program that terminates normally because of the 40 second sleep time. However, the er_print utility and Thread Analyzer report potential deadlocks.

% cc -g -o din_philo_pt din_philo.c
% collect -r deadlock -o din_philo_pt.1.er din_philo_pt 40
Creating experiment database tha.2.er ...
Philosopher 0 is done thinking and now ready to eat.
Philosopher 2 is done thinking and now ready to eat.
Philosopher 1 is done thinking and now ready to eat.
Philosopher 3 is done thinking and now ready to eat.
Philosopher 2: got right  chopstick 2
Philosopher 3: got right  chopstick 3
Philosopher 0: got right  chopstick 0
Philosopher 4 is done thinking and now ready to eat.
Philosopher 0: got left chopstick 1
Philosopher 0: eating.
Philosopher 3: got left chopstick 4
Philosopher 3: eating.
Philosopher 0: got left chopstick 1
Philosopher 0: eating.
Philosopher 0: got right  chopstick 0
Philosopher 2: got left chopstick 3
Philosopher 2: eating.
...
Philosopher 4: got right  chopstick 4
Philosopher 3: got right  chopstick 3
Philosopher 2: got right  chopstick 2
Philosopher 4: got left chopstick 0
Philosopher 4: eating.
Philosopher 4 is done eating.
Philosopher 3: got left chopstick 4
Philosopher 3: eating.
Philosopher 0: got right  chopstick 0
Philosopher 0: got left chopstick 1
Philosopher 0: eating.
Philosopher 3 is done eating.
Philosopher 2: got left chopstick 3
Philosopher 2: eating.
Philosopher 0 is done eating.
Philosopher 2 is done eating.
Philosopher 1: got right  chopstick 1
Philosopher 1: got left chopstick 2
Philosopher 1: eating.
Philosopher 1 is done eating.
%

Execution terminated normally

Type the following commands shown at the prompts to examine the experiment with er_print utility:

% er_print din_philo_pt.1.er
(er_print) deadlocks
Deadlock #1, Potential deadlock
        Thread #2
                Lock being held:        0x21388, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
                Lock being requested:   0x213a0, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
        Thread #3
                Lock being held:        0x213a0, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
                Lock being requested:   0x213b8, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
        Thread #4
                Lock being held:        0x213b8, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
                Lock being requested:   0x213d0, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
        Thread #5
                Lock being held:        0x213d0, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
                Lock being requested:   0x213e8, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
        Thread #6
                Lock being held:        0x213e8, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"
                Lock being requested:   0x21388, at: grab_chopstick + 0x00000024, line 105 in "din_philo.c"

Deadlocks List Summary: Experiment: din_philo_pt.1.er Total Deadlocks: 1

The following screen shot shows the potential deadlock information in Thread Analyzer.

Figure 3-4  Potential deadlock in din_philo.c

image:A screen shot of the Thread Analyzer window which shows a potential               deadlock.