Exercise 1.3: Identifying a thread bottleneck
Before you begin, you must complete Exercise 1.2 Collecting thread data.
Finding thread bottlenecks using the Thread View
The Thread View displays the status of all the threads in your application, and explicitly indicates thread deadlocks and contentions.
To find bottlenecks:
- In the Profiling Monitor, right-click the Profiling resource, and then select Open With > Thread View. The Thread View opens. It looks something like this:
The vertical arrows between threads are what interest us. An arrow indicates that one thread (the thread in which the arrow originates) is waiting for another thread (the thread to which the arrow is pointing) to release a lock.
- The arrows are too close to each other to be easily distinguished. To see them better, switch from the default linear time scale to a weighted time scale by clicking the Switch to Compressed Time Scale button
. The Compressed Time Scale compresses the time segments during which no significant thread action occurs. The display changes to something like this:
- Interpret the Thread View as follows:
- Note that soon after the program starts, four philo* threads are created. All of them run, then sleep, then run again briefly. When the program terminates, all of them have changed to a Waiting for Lock state.
Note: A distinct "Sleep" state cannot be displayed on some systems.
- The philo* threads are waiting for a lock from other philo* threads that are also waiting for a lock. In this case, we have a deadlock: The program reaches an impasse and cannot continue.
Note: You can see specific information about lock requests by pausing your cursor over the thread segment that is waiting for a lock. This displays a tool-tip that specifies the name of the lock and identifies the thread that is holding the lock (the "Locking Thread").
- You can see detailed information about thread segments in the Properties view. To display the view, select Windows > Show View > Properties. Select a thread segment to display its properties.
You now understand why this deadlock occurs. You are ready to begin Exercise 1.4: Resolving the thread bottleneck.