The following is thread safe since each array element is accessed by only one thread (including the real world part not shown here):
static bool myArray[THREAD_COUNT] = {false}; // Only used in DoSomething()
void DoSomething(uint8_t threadIndex)
{
myArray[threadIndex] = true;
// Real world function is more complex
}
Now consider the following code:
void DoSomething(uint8_t threadIndex)
{
static bool myArray[THREAD_COUNT] = {false};
myArray[threadIndex] = true;
// Real world function is more complex
}
Is this function threadsafe too (especially considering the array initialization that takes place at first call of the function, not at startup)?