Do threads have their own stack?
Or alternatively, is the stack safe in a multithreaded app (yes, I guess it must be but here's what I'm getting at - consider the following code)
Code:
int some_func()
{
static int x;
x = call_some_other_func();
return x;
}
I appreciate that if the above function was getting called from 2 different threads (without any thread synchronisation) it'd be a recipe for disaster because there's only one copy of 'x' being shared between two unsynchronised threads. But what if 'x' was a local variable...?
Code:
int some_func()
{
int x;
x = call_some_other_func();
return x;
}
Assuming that 'call_some_other_func()' was thread safe, is it safe to call the above function from two unsynchronised threads? Does each of them see a different copy of x?
"A problem well stated is a problem half solved.” - Charles F. Kettering