A mutex is used to prevent two or more threads to access the same resource (file, variable, ..) at the same time. This prevents a race condition to happen.
Every thread has its own stack. This means when a thread calls a function, the thread will have a unique copy of the local variables defined in this function. But if a local variable is defined as static, only one copy of this variable will be created and this copy will be accessed by all threads.
Does this mean that a local NON-
staticmutex is useless?Can a
staticlocal mutex be useful? Maybe for guarding astaticlocal variable?How does defining a global mutex as
staticmake as a difference?