Please enable JavaScript to view this site.

Thread Validator Help

 

Lock order dialog

 

Thread Validator can display the order in which locks and waits were entered.

 

The lock order dialog (i.e. Locks and Waits in Sequence Order dialog) can be started in two different ways:

 

All Locks tab instructionStep right_mouse_buttonpopup menu instructionStep Lock Acquisition Order...
 

menu Query menu instructionStep Display lock order

 

 lock-sequence-order-dialog

 

The dialog displays the order...

 

in which critical sections are locked and waited upon

 

that waits are entered into
 

in which threads sleep and are suspended

 

For this, you need to enable the Functions working with waitable handles option on the Hook Insertion settings page.

 

note You don't need to enable the individual Sleep option.

 

 

Data displayed in the table

 

Thread Id instructionStep displays the thread id and a thread name if one is available
 

Address instructionStep  the critical section address that is locked or being waited upon
 

For WaitForSingleObject calls, this is the handle that is being waited upon.

 

For WaitForMultipleObjects calls, the number of handles being waited upon is shown.

 

Sequence instructionStep displays the sequence id of the lock or wait
 

Green bars in this column indicate the sequence id relative to the known range of all ids.

 

Status instructionStep displays the word Locked or Waiting for critical sections

 

For WaitForSingleObject or WaitForMultipleObjects calls the appropriate function is displayed instead.

 

Member variable instructionStep shows information about the storage variable used when entering the critical section

 

Filename instructionStep displays the filename of the function where the critical section was entered

 

 

Understanding the data

 

The image below shows that three threads have deadlocked.

 

Each thread has acquired one lock and is waiting upon another, so there's two entries in this view for each thread.

 

lock-sequence-order-example

 

The order the threads acquired and is waiting upon locks is the same as the order of the data in the list, which is in turn the same as the sequence ids in the Sequence column.

 

This situation was caused by the bad lock strategy used in the example program.

 

In this example three threads are created - lets call them A, B and C - and each repeatedly attempts to lock two of the critical sections a,b and c as follows:

 

Thread A locks sections a and b and then unlocks b and a

 

Thread B locks sections b and c and then unlocks c and b

 

Thread C locks sections c and a and then unlocks a and c

 

It should be easy to see that a three lock circular deadlock will occur quickly occur as each thread waits for a lock that another thread has, and indeed this is what the image above shows us has happened.

 

 

Sleeping threads

 

When a sleeping thread is listed:

 

the Address column displays Thread

 

If the Hook Insertion settings has Functions working with waitable handles enabled:

 

the Sequence column indicates the sequence id for the start of the thread sleeping

 

The horizontal position of the green bar in this column changes to show relative size of the sequence id compared to the most recently allocated id.

 

the Status column displays Sleeping.

 

display-lock-order-sleeping

 

Suspended threads

 

When a suspended thread is listed:

 

the Address column displays Thread

 

If the Hook Insertion settings has Functions working with waitable handles enabled:

 

the Sequence column indicates the sequence id for the start of the thread suspension

 

the Status column displays Suspended

 

display-lock-order-suspended

 

Related threads

 

Selecting a critical section or wait handle in the list highlights (in grey) any other threads using the same critical section or handle (same address).

 

Any other occurrences of the same thread waiting on a lock or holding a lock will also be highlighted with the thread information colour (orange col-threadinfo by default).

 

 

lock-sequence-order-related

 

 

Updating the display

 

 

Auto Update instructionStep refresh the contents of the list once per second
 

Refresh instructionStep refresh the list manually when you need to

 

The green bars in the Sequence column are automatically updated periodically.

 

 

Menu Options

 

A popup menu is available by right clicking on any item in the list:

 

 lock-sequence-order-menu

 

 

right_mouse_buttonMenu option: Information about lock or wait

 

Information about lock/wait... instructionStep shows the relevant information dialog from those below, depending on the type of item selected

 

These information dialogs do not block the application so you can show as many as you need, either from this tab or others, and leave them open to compare or investigate later.

 

thread-information-dialog

 

critical-section-information

 

waitforsingleobkect-information-dialog

 

 

right_mouse_buttonMenu option: editing source code

 

Edit Source Code... instructionStep opens the default or preferred editor to edit the source code

 

 

right_mouse_buttonMenu options: show ... callstacks

 

Show Creation Callstack... instructionStep shows the callstack for the creation of this item, i.e. the locked or waiting critical section and thread

 

Show Lock Callstack... instructionStep shows the callstack for the locked or waiting critical section and thread

 

Show All Lock Callstacks (this thread)... instructionStep shows all callstacks for this critical section and only this thread

 

Show All Lock Callstacks (all threads)... instructionStep as above but for any thread