STL icon indicating copy to clipboard operation
STL copied to clipboard

No thread-safe annotations for mutex and related classes

Open JVApen opened this issue 1 year ago • 3 comments

The clang compiler comes with some very useful warnings under the umbrella of -Wthread-safety. (See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html) Unfortunately, the MS STL does not provide annotations to the relevant classes, such that this warning cannot be used with the standard STL types.

How about other implementations?

  • libc++ adds these annotations (https://github.com/llvm-mirror/libcxx/blob/master/include/mutex)
  • libstdc++ does not add these annotations (https://gcc.gnu.org/onlinedocs/gcc-12.1.0/libstdc++/api/a00143_source.html#l00692)

Would it be possible to decorate the thread safety analysis such that this warning can be used and prevent a lot of debugging time for threading issues that are easily caught by the compiler?

JVApen avatar Apr 02 '24 12:04 JVApen

This looks like duplicate of #3163.

It's a unfortunate that annotations in SAL for concurrency isn't designed for C++ lock types (https://github.com/microsoft/STL/pull/3536#issuecomment-1489352034).

But it seems possible to me to add annotations for Clang.

frederick-vs-ja avatar Apr 02 '24 12:04 frederick-vs-ja

Looks indeed like a duplicate of #3163

JVApen avatar Apr 02 '24 17:04 JVApen

Thanks! We'll use this newer issue as the primary since it talks only about Clang (and not SAL annotations which we've abandoned any attempt to use here).

StephanTLavavej avatar Apr 03 '24 21:04 StephanTLavavej