Bird
Raised Fist0
FreeRTOSprogramming~10 mins

Rendezvous (sync) pattern in FreeRTOS - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Rendezvous (sync) pattern
Task A waits at sync point
↓
Task B waits at sync point
↓
Both tasks reached sync
↓
Tasks proceed together
Two tasks wait for each other at a synchronization point, then both continue together.
Execution Sample
FreeRTOS
void taskA(void *pvParameters) {
  xSemaphoreTake(syncSemaphore, portMAX_DELAY);
  // Critical section after sync
  xSemaphoreGive(syncSemaphore);
  vTaskDelete(NULL);
}

void taskB(void *pvParameters) {
  xSemaphoreTake(syncSemaphore, portMAX_DELAY);
  // Critical section after sync
  xSemaphoreGive(syncSemaphore);
  vTaskDelete(NULL);
}
Two tasks wait on a semaphore to synchronize before proceeding.
Execution Table
StepTaskActionSemaphore CountResult
1Task AWaits on semaphore0Blocks, waiting
2Task BWaits on semaphore0Blocks, waiting
3ISR or InitGives semaphore twice2Semaphore count = 2
4Task ATakes semaphore1Unblocks, proceeds
5Task BTakes semaphore0Unblocks, proceeds
6Task AGives semaphore1Semaphore count incremented
7Task BGives semaphore2Semaphore count incremented
8Both tasksDelete themselves2Tasks end
9---Execution ends
💡 Both tasks have synchronized and completed their critical sections.
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 7Final
syncSemaphore count021022
Key Moments - 3 Insights
Why do both tasks block initially when waiting on the semaphore?
Because the semaphore count starts at 0, no task can take it immediately, so both block until the semaphore is given (see execution_table steps 1 and 2).
How does giving the semaphore twice help both tasks proceed?
Giving the semaphore twice increases its count to 2 (step 3), allowing both tasks to take it once each and unblock (steps 4 and 5).
Why do tasks give the semaphore back after taking it?
Giving the semaphore back allows the semaphore count to be restored, maintaining synchronization for possible future rendezvous (steps 6 and 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the semaphore count after Task A takes it at step 4?
A2
B0
C1
DNone
💡 Hint
Check the 'Semaphore Count' column at step 4 in the execution_table.
At which step do both tasks unblock and proceed?
AStep 3
BSteps 4 and 5
CStep 2
DStep 7
💡 Hint
Look for 'Unblocks, proceeds' in the Result column of execution_table.
If the semaphore was only given once at step 3, what would happen?
AOnly one task proceeds, the other blocks
BBoth tasks proceed immediately
CBoth tasks block forever
DSemaphore count becomes negative
💡 Hint
Refer to the semaphore count and blocking behavior in execution_table steps 1-5.
Concept Snapshot
Rendezvous pattern in FreeRTOS:
- Two tasks wait on a semaphore to sync.
- Semaphore count starts at 0; tasks block.
- ISR or init gives semaphore twice.
- Both tasks take semaphore and proceed together.
- Tasks give semaphore back to restore count.
Full Transcript
The Rendezvous synchronization pattern in FreeRTOS involves two tasks waiting on a semaphore initialized with count zero. Both tasks block when trying to take the semaphore. An external event or initialization gives the semaphore twice, increasing its count to two. This allows both tasks to take the semaphore once each and unblock, proceeding together past the synchronization point. After their critical section, tasks give the semaphore back to restore the count, allowing future synchronization. This pattern ensures tasks meet at a rendezvous point before continuing.

Practice

(1/5)
1. What is the main purpose of the Rendezvous (sync) pattern in FreeRTOS?
easy
A. To synchronize two tasks so they wait for each other before proceeding
B. To create multiple independent tasks running without coordination
C. To prioritize one task over another permanently
D. To allocate memory dynamically for tasks

Solution

  1. Step 1: Understand the Rendezvous pattern concept

    The Rendezvous pattern is designed to synchronize two tasks so that each waits for the other to reach a certain point before continuing.
  2. Step 2: Identify the purpose in FreeRTOS context

    In FreeRTOS, this synchronization is often done using semaphores to signal readiness and wait for the other task.
  3. Final Answer:

    To synchronize two tasks so they wait for each other before proceeding -> Option A
  4. Quick Check:

    Rendezvous = Synchronize tasks [OK]
Hint: Rendezvous means tasks meet and wait for each other [OK]
Common Mistakes:
  • Thinking it creates independent tasks without coordination
  • Confusing with task prioritization
  • Assuming it manages memory allocation
2. Which FreeRTOS primitive is typically used to implement the Rendezvous pattern?
easy
A. Mutex
B. Queue
C. Semaphore
D. Event Group

Solution

  1. Step 1: Recall synchronization primitives in FreeRTOS

    FreeRTOS provides mutexes, semaphores, queues, and event groups for task synchronization and communication.
  2. Step 2: Identify which primitive signals readiness and waits

    The Rendezvous pattern requires signaling and waiting between two tasks, which is best done using semaphores.
  3. Final Answer:

    Semaphore -> Option C
  4. Quick Check:

    Rendezvous uses semaphores [OK]
Hint: Semaphores signal and wait between tasks [OK]
Common Mistakes:
  • Choosing mutex which is for mutual exclusion, not sync
  • Confusing queues with direct signaling
  • Using event groups which are for multiple event flags
3. Consider two tasks using binary semaphores for Rendezvous. Task A signals semaphore S1 and waits on S2. Task B signals S2 and waits on S1. What happens if Task A runs first and signals S1 before Task B waits on it?
medium
A. Both tasks will run without blocking
B. Task B will block indefinitely waiting on S1
C. Task A will block indefinitely waiting on S2
D. Task B will unblock immediately when it waits on S1

Solution

  1. Step 1: Understand semaphore signaling and waiting

    If Task A signals semaphore S1 before Task B waits on it, the semaphore count becomes available.
  2. Step 2: Analyze Task B's wait on S1

    When Task B waits on S1, it finds the semaphore already signaled and unblocks immediately without waiting.
  3. Final Answer:

    Task B will unblock immediately when it waits on S1 -> Option D
  4. Quick Check:

    Signaled semaphore unblocks waiting task immediately [OK]
Hint: Semaphore signals persist until taken by waiting task [OK]
Common Mistakes:
  • Assuming tasks must wait even if semaphore is signaled
  • Thinking Task A blocks waiting on S2 first
  • Believing both tasks run without blocking always
4. Given this snippet for Rendezvous synchronization, what is the error?
void TaskA(void *pvParameters) {
  xSemaphoreGive(SemA);
  xSemaphoreTake(SemB, portMAX_DELAY);
  // Continue...
}

void TaskB(void *pvParameters) {
  xSemaphoreTake(SemA, portMAX_DELAY);
  xSemaphoreGive(SemB);
  // Continue...
}
medium
A. Tasks should not use semaphores for synchronization
B. Semaphores SemA and SemB are not created before use
C. xSemaphoreGive should be called after xSemaphoreTake in TaskA
D. portMAX_DELAY is invalid for xSemaphoreTake

Solution

  1. Step 1: Check semaphore initialization

    Before using semaphores, they must be created with xSemaphoreCreateBinary or similar functions.
  2. Step 2: Identify missing creation

    The code snippet does not show creation of SemA and SemB, which will cause runtime errors or undefined behavior.
  3. Final Answer:

    Semaphores SemA and SemB are not created before use -> Option B
  4. Quick Check:

    Semaphores must be created before giving or taking [OK]
Hint: Always create semaphores before using them [OK]
Common Mistakes:
  • Thinking order of give/take is wrong here
  • Believing semaphores are not for synchronization
  • Misunderstanding portMAX_DELAY usage
5. You want two tasks to synchronize at multiple points using the Rendezvous pattern. Which approach ensures no deadlock if one task signals twice before the other waits?
hard
A. Use counting semaphores instead of binary semaphores
B. Use mutexes to lock and unlock tasks
C. Use queues to send messages instead of semaphores
D. Use event groups with a single bit flag

Solution

  1. Step 1: Understand semaphore types and their behavior

    Binary semaphores can only hold one signal at a time, so signaling twice before waiting can cause lost signals and deadlock.
  2. Step 2: Identify solution to handle multiple signals

    Counting semaphores can hold multiple signals, allowing tasks to signal multiple times without losing signals, preventing deadlock.
  3. Final Answer:

    Use counting semaphores instead of binary semaphores -> Option A
  4. Quick Check:

    Counting semaphores handle multiple signals safely [OK]
Hint: Counting semaphores count signals, preventing lost sync [OK]
Common Mistakes:
  • Using mutexes which do not count signals
  • Using queues which add complexity
  • Using event groups with single bits only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard