A mutex is the basic synchronization mechanism used to protect critical sections within a thread. Mutexes are used to implement protected objects. The mutex allows one thread mutually exclusive access to a resource. Mutexes are useful when only one thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should only be allowed by one thread at a time. By using a mutex to control the linked list, only one thread at a time can gain access to the list.
The Rational® Rhapsody® implementation of a mutex is as a recursive lock mutex. This means that the same thread can lock the mutex several times without blocking itself. In other words, the mutex is actually a counted semaphore. When implementing OMOSMutex for the target environment, you should implement it as a recursive lock mutex.
Mutexes can be either free or locked (they are initially free). When a task executes a lock operation and finds a mutex locked, it must wait. The task is placed on the waiting queue associated with the mutex, along with other blocked tasks, and the CPU scheduler selects another task to execute. If the lock operation finds the mutex free, the task places a lock on the mutex and enters its critical section. When any task releases the mutex by calling free, the first blocked task in the waiting queue is moved to the ready queue, where it can be selected to run according to the CPU scheduling algorithm.
The same thread can nest lock and free calls of the same mutex without indefinitely blocking itself. Nested locking by the same thread does not block the locking thread. However, the nested locks are counted so the proper free actually releases the mutex.