3 Semaphores Flashcards
What are the advantages of task synchronisation?
Task Synchronisation makes it possible for tasks to co-ordinate and co-operate.
Can be used to communicate between tasks.
Can be used to protect shared data.
Name the types of semaphores
Binary, counting, and mutex
Describe binary semaphores
Binary - Implements synchronisation between tasks or between interrupt handlers and tasks. An attempt to take a semaphore will block unless the semaphore has been given by another task or interrupt handler.
Can be given infinite times but only taken once.
Describe counting semaphores
Counting- Has a count variable associated with it.
Giving the semaphore increments the count
Taking the semaphore decrements the count
Can be used for counting events to ensure that no events lost.
Describe a mutex
Mutex – Token used to guard a resource.
Only the task with mutex can access the resource.
When a mutex is taken, it must be given back
How would you create a binary semaphore?
Define a variable of type SemaphoreHandle_t
SemaphoreHandle_t SW_Semaphore=NULL;,
SW_Semaphore = xSemaphoreCreateBinary();
How do you give or take a semaphore?
xSeamphoreGive() and xSemaphoreTake()
What is a deadlock?
A deadlock is where 2 tasks cannot proceed because they are both waiting on a resource held by the other.