Miosix also provides primitives, in order to synchronize the execution of multiple threads, such as mutexes and condition variables.
A mutex can be created as a global variable. Note that `Mutex` is a C++ class, and thus it has a constructor, so it initializes itself. The Miosix API provides two mutex classes: `Mutex` and `FastMutex`. `Mutex` has support for priority inheritance, while `FastMutex` is optimized for fastest lock/unlock.
A mutex can also be part of a data structure. Note that even if this is a struct, the fact that it contains C++ class means it MUST be allocated with new and not with malloc(), because malloc() does not know about C++ constructors and would leave the mutex not initialized.
A mutex can also be part of a data structure. Note that even if this is a struct, the fact that it contains C++ class means it MUST be allocated with new and not with `malloc()`, because `malloc()` does not know about C++ constructors and would leave the mutex not initialized.
> :warning: **Try to always keep the critical section in which a mutex is locked as small as possible.**