The example application is a great way to explore the capabilities of Thread Validator.
The source and projects are included in the installation, but you'll need to build the example application yourself.
You can then use nativeExample.exe in conjunction with Thread Validator to generate thread errors, waits, deadlocks and potential deadlocks, and monitor the behaviour of the application as you use it.
After launching the example application from Thread Validator, the following dialog appears showing counters reflecting the status of various tests you can run from the Test menu.
The best way to understand how Thread Validator works is by example.
We recommend launching the example application from Thread Validator and observing how the menu actions affect threads, locks and synchronization objects.
Examining the source code is the best way to see what's going on in the example application.
The examples create threads and engage critical sections in different scenarios. For convenience, below we have provided the source locations where each menu action runs a test.
Most test locations are in the CTeststakView class of nativeExample\TESTSVW.CPP
File menu Exit closes the example application
Test menu ...
2 Thread deadlock |
OnHandlesStartthread1() OnHandlesStartthread2() Creates two named threads that increment counter1 and counter 2 in the midst of repeatedly locking and unlocking two critical sections with an interim Sleep.
Sooner or later the two threads will deadlock and the counters being updated in the view will stop.
|
3 Thread deadlock |
OnHandlesStartthreadA() OnHandlesStartthreadB() OnHandlesStartthreadC()
Creates three named threads that increment counterA,B,C in the midst of repeatedly locking and unlocking three critical sections with interim Sleeps.
Sooner or later the threads will deadlock and the counters being updated in the view will stop.
|
Start 2 Thread deadlock |
OnTestStart2ThreadDeadlock() Combines the above 2 Thread deadlock operations into a single function.
|
Start 3 Thread deadlock |
OnTestStart3threaddeadlock() Creates three named threads that increment counter3A,3B,3C in the midst of repeatedly locking and unlocking two of three critical sections with no interim Sleeps, and with a circular dependency.
The threads will deadlock and the counters being updated in the view will stop.
|
Start 3 Thread deadlock (two) |
OnTestStart3threaddeadlock2()
The threads will still soon deadlock and the counters being updated in the view will stop.
|
Start 2 Thread deadlock with infinite wait |
OnTestStart3threaddeadlockwithinfinitewait() |
Start 2 Thread deadlock with thread suspend |
OnTestStart3threaddeadlockwiththreadsuspend()
|
Start 2 Thread deadlock with infinite sleep |
OnTestStart3threaddeadlockwithinfinitesleep()
See comments in this function for an explanation. Deadlock occurs when CounterSleepIa,Ib stop incrementing.
|
Bad lock strategy example |
OnTestBadlockstrategyexample()
Create two threads that both use the same incorrect lock strategy. These two threads exhibit a bad lock strategy, but will probably not deadlock each other for a long time.
Deadlock occurs when CounterBa,Bb stop changing.
|
Good lock strategy example |
OnTestGoodlockstrategyexample() Create two threads that both uses a good lock strategy. These two threads should never deadlock.
Deadlock occurs when CounterGa,Gb,Gc shouldn't stop changing. |
Good lock strategy example (faster) |
OnTestGoodlockstrategyexampleEx()
As above but much faster.
|
Create deadlock then determine stack traces |
OnTestCreatedeadlockthendeterminestacktraces()
Forces a deadlock with two threads and leaves them running so that Thread Validator can determine stack traces
|
Recursion test |
OnTestRecursiontest()
Enters the same critical section 3 times in a row.
|
Leave non-entered critical section |
OnTestLeavenonenteredcriticalsection()
|
Delete still active critical section |
OnTestDeletestillactivecriticalsection()
Enters a critical section once and then deletes it without leaving.
|
Leave critical sections in the wrong order |
OnTestLeavecriticalsectionsinthewrongorder()
Simple test to lock three sections and then unlock them in the same order instead of the reverse order.
|
Potential deadlock 2 threads |
OnTestPotentialdeadlock2threads()
Two threads enter and leave four critical sections, but two of them are in different orders to the other thread. There is a potential for deadlock here.
|
Potential deadlock 3 threads |
OnTestPotentialdeadlock3threads()
Two threads enter and leave four critical sections, but three of them are in different orders to the other thread. There is a potential for deadlock here.
|
Test ExitThread() |
OnTestTestexitthread()
Creates two named threads, one of which explicitly calls ExitThread.
|
Force crash inside a locked critical section (part 1) |
OnTestForcecrashinsidecrtleavingapermanentlockoncrtthendeadlock()
These functions has changed their mechanism due to Microsoft CRT fixes. |
Force crash inside a locked critical section (part 2) |
OnTestForcecrashinsidecrtpart2()
When preceded by part 1 (above) this call should deadlock (cause an infinite wait on a contended lock) as the lock is held by the waiting main UI thread that crashed before unlocking the critical section.
|
Help menu ...
About Thread Validator Tester |
nativeExampleApp::OnAppAbout()
Shows a simple information dialog using code in nativeExample.cpp
|