Quote:
Originally Posted by jwakeman
Can someone explain the difference between these two uses of the semaphore? I see both being used in the PIDController class.
Code:
CRITICAL_REGION(m_semaphore)
{
}
END_REGION;
Code:
{
Synchronized sync(m_semaphore);
}
|
the first is a semaphore used for mutual exclusion (to protect the critical region), in this use-case the semaphore is taken before and given after a critical region of code and always in the same context - the semaphore includes the concept of ownership (by the thread/task) and recursion
the second is a semaphore used for synchronization, in this use-case the semaphore is taken in one context/thread/task and given or flushed in another context - for example given/flushed in a periodic timer callback function (or maybe an interrupt service routine) and taken in a task/thread
hth