Challenge - 5 Problems
Task Pooling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of task creation with dynamic pooling
Consider a FreeRTOS system where tasks are created dynamically from a pool. What will be the output of the following code snippet when three tasks are created and run?
FreeRTOS
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void vTaskFunction(void *pvParameters) { int id = *((int *)pvParameters); printf("Task %d running\n", id); vTaskDelete(NULL); } int main() { TaskHandle_t xTaskHandles[3]; int task_id; for (int i = 0; i < 3; i++) { task_id = i + 1; xTaskCreate(vTaskFunction, "Task", 1000, &task_id, 1, &xTaskHandles[i]); } vTaskStartScheduler(); return 0; }
Attempts:
2 left
💡 Hint
Consider what happens when the same memory address is passed to multiple tasks.
✗ Incorrect
All tasks receive the address of the same variable in the loop, which changes before tasks run, so all print the last value (3).
🧠 Conceptual
intermediate1:30remaining
Best practice for task parameter passing in dynamic pools
In FreeRTOS, when creating multiple tasks dynamically from a pool, what is the best practice to ensure each task receives a unique parameter?
Attempts:
2 left
💡 Hint
Think about how memory addresses and values behave when tasks start asynchronously.
✗ Incorrect
Each task must have its own unique parameter memory to avoid all tasks reading the same changing value.
🔧 Debug
advanced2:00remaining
Identify the cause of task starvation in a dynamic pool
Given a FreeRTOS system with a task pool managing dynamic workloads, tasks sometimes never run. What is the most likely cause?
FreeRTOS
void vTaskFunction(void *pvParameters) {
while(1) {
// Process workload
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
int main() {
for (int i = 0; i < 5; i++) {
xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, NULL);
}
vTaskStartScheduler();
return 0;
}Attempts:
2 left
💡 Hint
Consider how FreeRTOS schedules tasks with the same priority.
✗ Incorrect
Tasks with the same priority share CPU time fairly, so starvation does not occur here.
📝 Syntax
advanced1:30remaining
Identify the syntax error in task creation code
Which option contains a syntax error in FreeRTOS task creation?
FreeRTOS
void vTaskFunction(void *pvParameters) {
// Task code
}
int main() {
TaskHandle_t xHandle;
xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xHandle);
vTaskStartScheduler();
return 0;
}Attempts:
2 left
💡 Hint
Check the type of the second argument in xTaskCreate.
✗ Incorrect
The second argument must be a string literal or char pointer, not an identifier without quotes.
🚀 Application
expert2:30remaining
Calculate maximum concurrent tasks in a dynamic pool
A FreeRTOS system has 64KB of heap memory. Each task requires 2KB stack and 512 bytes for task control block (TCB). If the system reserves 8KB for other uses, what is the maximum number of tasks that can be created dynamically in a task pool?
Attempts:
2 left
💡 Hint
Calculate available memory and divide by total memory per task (stack + TCB).
✗ Incorrect
Available memory = 64KB - 8KB = 56KB = 57344 bytes. Each task uses 2KB + 512B = 2560 bytes. 57344 / 2560 = 22.4, so max 22 tasks.