Complete the code to create a binary semaphore for synchronization.
SemaphoreHandle_t syncSemaphore = xSemaphoreCreate[1]();The rendezvous pattern uses a binary semaphore to synchronize tasks. The function xSemaphoreCreateBinary() creates such a semaphore.
Complete the code to wait indefinitely for the semaphore to be given.
if (xSemaphoreTake(syncSemaphore, [1]) == pdTRUE) { // Proceed after synchronization }
Using portMAX_DELAY makes the task wait indefinitely until the semaphore is available, which is typical in rendezvous synchronization.
Fix the error in the code to give the semaphore from an ISR correctly.
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(syncSemaphore, [1]);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);The function xSemaphoreGiveFromISR() requires a pointer to xHigherPriorityTaskWoken to correctly manage context switching after ISR.
Fill both blanks to create a rendezvous where two tasks wait and signal each other using semaphores.
void Task1(void *pvParameters) {
// Wait for Task2
xSemaphoreTake(syncSemaphore, [1]);
// Signal Task2
xSemaphoreGive([2]);
}Task1 waits indefinitely for syncSemaphore and then signals otherSemaphore to synchronize with Task2.
Fill all three blanks to implement a rendezvous pattern where TaskA and TaskB synchronize using two semaphores.
void TaskA(void *pvParameters) {
xSemaphoreGive([1]);
xSemaphoreTake([2], [3]);
// Continue after rendezvous
}TaskA signals semA to notify TaskB, then waits indefinitely on semB to complete the rendezvous synchronization.
