You’ve written a multi-thread application, you’ve implemented a locking strategy, but data is being corrupted. Why is that happening?
One possible reason is that the locking strategy is faulty. A manual review says it’s good, but real world experience says otherwise. What can cause that?
Many locking primitives have “default unlocked” conditions. If these are setup in the default condition, visually they look OK, but they don’t lock the lock when it is acquired.
void function() { CSingleLock lock(&critSect); doProtectedWork(); }
Locks configured in this manner are effectively impotent. You need a tool that can scan for such conditions and report them to you.
Thread Lock Checker is a software tool that scans source code looking for various usage types of single and multiple critical section locking classes, such as CSingleLock and CMultiLock.
Thread Lock Checker scans all source files under a specified disk hierarchy. When usage types are found that match the criteria specified in the settings the usage is reported on the lock report.
In the lock report shown above 11 matches have been found for CSingleLock criteria that match the settings. These include:
Clicking on an entry in the lock report will shown the source code in the source code viewer. The line of interest is highlighted in green.
Double clicking on an entry in the lock report will start Visual Studio to edit the source code.
Additional class names can be specified so that you can search for your own classes that implement similar behaviour.
You can automate this checking by using Thread Lock Checker from the command line. Add automated checking to your code review process, source code check in process, or to your software release process.
Example 1 Scan a directory looking for locking errors and output the results to a log file. If there are no results, there will be no log file.
threadLockChecker.exe /dir e:\om\c\ /output e:\test.txt
Example 2 Scan a directory looking for only CSingleLock and output the results to a log file. If there are no results, there will be no log file.
threadLockChecker.exe /dir e:\om\c\ /output e:\test.txt /removeAllLockTypes /addLockType CSingleLock
We also provide the following threading tools: