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
...
|
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.
|
|
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.
|
|
OnTestStart2ThreadDeadlock() Combines the above 2 Thread deadlock operations into a single function.
|
|
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.
|
|
OnTestStart3threaddeadlock2()
The threads will still soon deadlock and the counters being updated in the view will stop.
|
|
OnTestStart3threaddeadlockwithinfinitewait() |
|
OnTestStart3threaddeadlockwiththreadsuspend()
|
|
OnTestStart3threaddeadlockwithinfinitesleep()
See comments in this function for an explanation. Deadlock occurs when CounterSleepIa,Ib stop incrementing.
|
|
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.
|
|
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. |
|
OnTestGoodlockstrategyexampleEx()
As above but much faster.
|
|
OnTestCreatedeadlockthendeterminestacktraces()
Forces a deadlock with two threads and leaves them running so that Thread Validator can determine stack traces
|
|
OnTestRecursiontest()
Enters the same critical section 3 times in a row.
|
|
OnTestLeavenonenteredcriticalsection()
|
|
OnTestDeletestillactivecriticalsection()
Enters a critical section once and then deletes it without leaving.
|
|
OnTestLeavecriticalsectionsinthewrongorder()
Simple test to lock three sections and then unlock them in the same order instead of the reverse order.
|
|
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.
|
|
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.
|
|
OnTestTestexitthread()
Creates two named threads, one of which explicitly calls ExitThread.
|
|
OnTestForcecrashinsidecrtleavingapermanentlockoncrtthendeadlock()
These functions has changed their mechanism due to Microsoft CRT fixes. |
|
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
...
|
nativeExampleApp::OnAppAbout()
Shows a simple information dialog using code in nativeExample.cpp
|