我可以在 Windows 10 上使用 Thread Sanitizer 吗?

Can I use Thread Sanitizer on Windows 10?

我想在 windows 10(64 位)上用 C++ 测试数据竞争,但似乎 。 因此,我安装了 Cygwin 并获得了 g++ 11.2.0,尝试使用 -fsanitize=thread -fPIE -pie -g 编译我的 C++ 代码,但失败并出现 -ltsan not found 错误。

The doc 没有提到 Windows。甚至可以在 Windows 上使用 Thread Sanitizer?如果是,怎么做?

您链接的消毒剂是在 Clang 中实现的,而不是 MSVC 或 gcc。 您可以将 clang 与 Visual Studio 一起使用。为此,您需要安装适当的工具链。 您可以通过 cygwin 或 WSL 直接在 Windows 上 运行 clang。

此外,您能否 post 完整的编译命令(例如通过 godbolt.org)?

例如:https://godbolt.org/z/fax6o9E1f

只需使用 WSL 并在其上使用线程清理器。