Blocking Mutex of the QXK preemptive kernel.
- Details
- QP::QXMutex is a blocking mutual exclusion mechanism that can also apply the priority-ceiling protocol to avoid unbounded priority inversion (if initialized with a non-zero ceiling priority, see QXMutex::init()). In that case, QP::QXMutex requires its own unique QP priority level, which cannot be used by any thread or any other QP::QXMutex.
If initialized with preemption-ceiling of zero, QP::QXMutex does not use the priority-ceiling protocol and does not require a unique QP priority (see QXMutex::init()).
QP::QXMutex is recursive (re-entrant), which means that it can be locked multiple times (up to 255 levels) by the same thread without causing deadlock.
QP::QXMutex is primarily intended for the extended (blocking) threads, but can also be used by the basic threads through the non-blocking QXMutex_tryLock() API.
- Note
- QP::QXMutex should be used in situations when at least one of the extended threads contending for the mutex blocks while holding the mutex (between the QXMutex_lock() and QXMutex_unlock() operations). If no blocking is needed while holding the mutex, the more efficient non-blocking mechanism of selective QXK scheduler locking should be used instead. Selective scheduler locking is available for both basic threads and extended threads, so it is applicable to situations where resources are shared among all these threads.
- Usage
- The following example illustrates how to instantiate and use the mutex to protect a shared resource (random seed of a pseudo-random number generator).
. . .
TH_mutex.init(APP::N_PHILO + 6U);
for (;;) {
. . .
TH_mutex.lock(QP::QXTHREAD_NO_TIMEOUT);
QP::QXThread::delay(5U);
TH_mutex.unlock();
}
}
Blocking Mutex of the QXK preemptive kernel.
eXtended (blocking) thread of the QXK preemptive kernel