Google Releases New ThreadSanitizer Data Race Detection Tool
The new ThreadSanitizer Version 2 helps developers find even more threading errors in code so that bugs can be reduced and systems can be made more efficient.Google's latest ThreadSanitizer tool has been updated to Version 2, giving the five-year-old tool improved capabilities to help developers find more coding problems in less time than in the past. ThreadSanitizer (aka TSan) is a runtime data race detector based on binary translation, which was originally developed by Google engineers in 2009, wrote Alexander Potapenko, a Google software engineer, in an April 21 post on The Chromium Blog. "The tool helped find thousands of threading errors in various projects, including almost 180 bugs in Chromium. In 2010, we started experimenting with compiler-based instrumentation instead of binary translation, and once the approach had proven itself, our team redesigned ThreadSanitizer from scratch, focusing on compile-time instrumentation for greater speed and accuracy." Now the team has pushed the development of ThreadSanitizer v2 even farther, he wrote. Now part of both LLVM and GCC, the new tool is "able to detect data races in C++ and Go code, but it is also able to report synchronization issues like deadlocks, unjoined threads, destroying locked mutexes, use of async-signal unsafe code in signal handlers, and others."
The improved ThreadSanitizer v2 "recognizes atomic operations, so it produces far more accurate reports and can also find bugs in lock-free algorithms, which are hard to detect otherwise," wrote Potapenko. "For example, it has helped us find incorrect synchronization in LazyInstance, incorrect lock-free queue implementation and issues with concurrent sweeping in V8."
ThreadSanitizer v2 is up to 20 times faster than the old ThreadSanitizer, "which makes it possible to use it for heavyweight browser tests," he wrote. "Thanks to this, we've found several bugs in code that weren't covered by smaller unit tests, like races on the WebKit strings, garbage collection in Blink, a use-after-free in Blink, a handful of reports in WebRTC and many more. This has also improved bug reproducibility: The more times the test is repeated, the higher the chance to reproduce a flaky bug." Almost 100 bugs were detected by the new tool in the last six months, he wrote. "Our future plans include extensive use of TSan on ClusterFuzz and adding regular testing for various Chromium subprojects to catch new regressions quickly," wrote Potapenko.
Developers can find more information on using the improved tools on the ThreadSanitizer page, he wrote. "The tool is easy to use and can be integrated with any build system: just add a single compile-time flag and run the program to see the error reports. For Chromium developers, there's a special page with instructions on dev.chromium.org."