0

I have a program here which fails when run with thread sanitizer and I have no idea why. Does thread sanitizer not support this case (in which case the error is a false positive?)? Or is this is a bug in the program? If it is a bug, why is it a bug? The code listing is also shown below.

#include <vector>
class A{
    std::vector<int> a_;
    public:
    A()
    {
        a_ = std::vector<int>{1,2,3,4};
    }
    auto const& a() const  { return a_;}
};

int main()
{
    std::vector<A> list(100);
    std::vector<std::vector<int>> g(100);
    #pragma omp parallel for
    for(std::size_t i=0; i < 100; ++i){
        g[i] = list[i].a();
    }
}

This is not a duplicate because of this bugfix.

3
  • Possible duplicate of Can I use Thread Sanitizer for OpenMP programs?. Your code is perfectly fine. Commented Feb 16, 2018 at 12:47
  • Does that statement hold even after this bugfix? Commented Feb 16, 2018 at 12:53
  • Well I guess you could consider it a different question. While I appreciate your cloneable-minimal reproducible example. It is important to include the necessary specification (compiler, compilation line, compiler version, how you installed the compiler) and most importantly the error itself in your question. Nevertheless I suspect the answer is still the same. Commented Feb 16, 2018 at 18:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.