ThreadSanitizer(TSan)主要用于测试data races(数据竞争)。
有时ThreadSanitizer报告无法恢复堆栈,报错信息类似这样:
Previous read by thread 39: [failed to restore the stack]
可以通过调整history_size
值大小来解决。例如:
TSAN_OPTIONS="history_size=7"
history_size
意义:
Per-thread history size, controls how many previous memory accesses are remembered per thread. Possible values are [0..7]. history_size=0 amounts to 32K memory accesses. Each next value doubles the amount of memory accesses, up to history_size=7 that amounts to 4M memory accesses. The default value is 2 (128K memory accesses). If you consistently see only one stack trace in reports, you may try increasing the value of the flag but keep in mind that it increases memory consumption.