C++ multithread safe local variables?

Viewed 7408

I know that that question may be seemed as a duplicate, but I haven't got the answer reading the other questions.

My situation - Visual C++ compiler 2005 from express edition studio + Windows sdk.

Just a question if a function like that:

void myFunc()
{
    int i=0;
    i++;
}

is safe to call from multiple threads?

Yes, it seems like it is, but won't the compiler make the i variable be static in the memory? So that could lead to that two threads are acting together on one memory region? Or my fears are just some fears of a fool? And all local variables are created in the moment of calling the function?

4 Answers
Related