Alex
Alex

Reputation: 10126

Identifying thread unsafe data structures used by different threads simultaneously

There is a legacy project that contains hundreds of thousands SLOC and runs a lot of different threads.

There is a data structure that contains non-atomic member, that theoretically may be used by different threads, but due to high complexity of code it may be difficult to identify this case from a simple code analysis.

Timings not always cause the crash but it may happen (e.g. this member uses heap).

Is there any way to identify such variables or e.g. during the testing make application crash during the first access of this variable by thread that is different from the thread that accessed it before?

Upvotes: 0

Views: 63

Answers (1)

Vittorio Romeo
Vittorio Romeo

Reputation: 93324

You can try using clang++ with ThreadSanitizer. This involves recompiling your code with -fsanitize=thread -ltsan, and executing it. TSan should detect data races and give you stack traces to figure out what's causing them.

ThreadSanitizer is a tool that detects data races. It consists of a compiler instrumentation module and a run-time library. Typical slowdown introduced by ThreadSanitizer is about 5x-15x. Typical memory overhead introduced by ThreadSanitizer is about 5x-10x.

Upvotes: 1

Related Questions