NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages
mutex

In NXC the mutex type is a 32-bit value that is used to synchronize access to resources shared across multiple threads.

For this reason there is never a reason to declare a mutex variable inside a task or a function. It is designed for global variables that all tasks or functions can Acquire or Release in order to obtain exclusive access to a resource that other tasks or functions are also trying to use.

mutex motorMutex;
task t1()
{
while (true) {
Acquire(motorMutex);
// use the motor(s) protected by this mutex.
Release(motorMutex);
}
}
task t2()
{
while (true) {
Acquire(motorMutex);
// use the motor(s) protected by this mutex.
Release(motorMutex);
}
}
task main()
{
Precedes(t1, t2);
}