In spite of using the system of tokens, the Thread Analyzer reports a potential deadlock for this implementation even though none exists. This is a false positive. Consider the following screen-shot which details the potential deadlock:
Select the first thread in the chain (Thread #2) and then click on the
Dual Source tab to see the source code location in which Thread #2 held the
lock at address 0x215a8
, and where in the source
code it requested the lock at address 0x215c0
. The
following screen-shot shows the Dual Source tab for Thread #2.
The get_token() function in din_philo_fix1.c uses
a while loop to synchronize the threads. A thread will
not leave the while
loop until it successfully gets
a token (this occurs when num_can_eat
is greater
than zero). The while
loop limits the number of simultaneous
diners to four. However, the synchronization implemented by the while
loop is not recognized by the Thread Analyzer. It assumes that
all five philosophers attempt to grab the chopsticks and eat concurrently,
so it reports a potential deadlock. The following section details how to
limit the number of simultaneous diners by using synchronizations which the
Thread Analyzer recognizes.