Challenge - 5 Problems
Rendezvous Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Rendezvous synchronization with two tasks
Consider two FreeRTOS tasks using a binary semaphore to synchronize at a rendezvous point. What will be the output sequence printed by the tasks?
FreeRTOS
#include "FreeRTOS.h" #include "task.h" #include "semphr.h" #include <stdio.h> SemaphoreHandle_t xSemaphore; void Task1(void *pvParameters) { printf("Task1: Start\n"); xSemaphoreGive(xSemaphore); // Signal Task2 xSemaphoreTake(xSemaphore, portMAX_DELAY); // Wait for Task2 printf("Task1: End\n"); vTaskDelete(NULL); } void Task2(void *pvParameters) { xSemaphoreTake(xSemaphore, portMAX_DELAY); // Wait for Task1 printf("Task2: Start\n"); xSemaphoreGive(xSemaphore); // Signal Task1 printf("Task2: End\n"); vTaskDelete(NULL); } int main() { xSemaphore = xSemaphoreCreateBinary(); xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL); xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL); vTaskStartScheduler(); return 0; }
Attempts:
2 left
💡 Hint
Think about how the semaphore controls the order of execution between the two tasks.
✗ Incorrect
Task1 starts and signals Task2 by giving the semaphore. Task2 waits for the semaphore, then starts and signals back to Task1. This ensures Task2's start and end print statements happen between Task1's start and end.
🧠 Conceptual
intermediatePurpose of Rendezvous pattern in FreeRTOS
What is the main purpose of using the Rendezvous (synchronization) pattern in FreeRTOS task design?
Attempts:
2 left
💡 Hint
Think about what synchronization means in multitasking.
✗ Incorrect
The Rendezvous pattern ensures tasks wait for each other at a synchronization point, so they proceed together only after all have reached that point.
🔧 Debug
advancedIdentify the error causing deadlock in Rendezvous implementation
Given the following FreeRTOS code snippet implementing a rendezvous with two tasks, identify the cause of deadlock:
FreeRTOS
#include "FreeRTOS.h" #include "task.h" #include "semphr.h" #include <stdio.h> SemaphoreHandle_t xSemaphore1, xSemaphore2; void TaskA(void *pvParameters) { printf("TaskA: Before sync\n"); xSemaphoreGive(xSemaphore1); xSemaphoreTake(xSemaphore2, portMAX_DELAY); printf("TaskA: After sync\n"); vTaskDelete(NULL); } void TaskB(void *pvParameters) { printf("TaskB: Before sync\n"); xSemaphoreTake(xSemaphore1, portMAX_DELAY); xSemaphoreGive(xSemaphore2); printf("TaskB: After sync\n"); vTaskDelete(NULL); } int main() { xSemaphore1 = xSemaphoreCreateBinary(); xSemaphore2 = xSemaphoreCreateBinary(); xTaskCreate(TaskA, "TaskA", 1000, NULL, 1, NULL); xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL); vTaskStartScheduler(); return 0; }
Attempts:
2 left
💡 Hint
Check if any semaphore is given before the other task tries to take it.
✗ Incorrect
Both semaphores start empty. TaskA gives xSemaphore1, TaskB waits on it. TaskB gives xSemaphore2, TaskA waits on it. But if TaskA runs first and gives xSemaphore1, TaskB can proceed. However, if TaskB runs first and tries to take xSemaphore1 before TaskA gives it, it blocks. This can cause deadlock if scheduling is unlucky.
📝 Syntax
advancedIdentify the syntax error in Rendezvous semaphore usage
Which option contains a syntax error in the semaphore take/give calls for FreeRTOS rendezvous pattern?
Attempts:
2 left
💡 Hint
Check the syntax of function calls and commas.
✗ Incorrect
Option B is missing a comma between parameters in xSemaphoreTake call, causing a syntax error.
🚀 Application
expertNumber of synchronization points in a multi-task rendezvous
In a FreeRTOS system, four tasks must synchronize at a rendezvous point so that none proceeds until all have reached it. Using binary semaphores for pairwise synchronization, how many semaphore give/take operations are needed in total for all tasks to pass the rendezvous once?
Attempts:
2 left
💡 Hint
Consider that each task must wait for all others and signal all others.
✗ Incorrect
Each of the 4 tasks must wait for the other 3 tasks and signal the other 3 tasks. Each wait and signal is a semaphore take or give. So total operations = 4 tasks * 3 waits + 4 tasks * 3 signals = 24 operations. But since each semaphore operation is counted once per pair, total unique operations are 12 (each pair has 2 operations).
