My question is an extension to this question.
In the original question, the OP asked whether the local variables of a static function need to be protected against data races. The answer was that each thread gets its own stack frame. Is it safe to assume the same applies to nested classes with static functions?
// Function called by several threads
int someFunc(int a, int b)
{
struct nestedStruct
{
static int do_something(int& a, int& b)
{
a = rand();
b = rand();
return a + b;
}
};
return nestedStruct::do_something(a, b);
}
The outer
someFunchas its own stack frame, so ifrandis thread safe (I’m not sure if it is) then both the outer function and nested static function are fine.