Search code examples
c++pragma

Is std::polar thread safe?


Is the function std::polar() thread safe?

I would like to call the #pragma directive on a for that uses it inside.


Solution

  • Yes, std::polar is thread-safe (for some definition of thread-safe). See [res.on.data.races]/3:

    A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non- const arguments, including this.

    Since std::polar only takes const parameters, it does not modify any objects outside the thread that it is called from.