0
0
FreeRTOSprogramming~20 mins

Task pooling for dynamic workloads in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Task Pooling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
ATask 1 running\nTask 2 running\nTask 3 running\n
BTask 1 running\nTask 1 running\nTask 1 running\n
CTask 3 running\nTask 3 running\nTask 3 running\n
DNo output, system hangs
Attempts:
2 left
💡 Hint
Consider what happens when the same memory address is passed to multiple tasks.
🧠 Conceptual
intermediate
1: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?
APass the address of a loop variable directly to each task.
BAllocate or use distinct memory for each task's parameter before creation.
CUse a global variable shared by all tasks.
DDo not pass any parameter; use global constants instead.
Attempts:
2 left
💡 Hint
Think about how memory addresses and values behave when tasks start asynchronously.
🔧 Debug
advanced
2: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;
}
ATasks have equal priority but the scheduler is not started.
BTasks block indefinitely, causing starvation.
CThe idle task priority is higher than created tasks, starving them.
DAll tasks have the same priority, causing round-robin scheduling and no starvation.
Attempts:
2 left
💡 Hint
Consider how FreeRTOS schedules tasks with the same priority.
📝 Syntax
advanced
1: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;
}
AxTaskCreate(vTaskFunction, Task, 1000, NULL, 1, &xHandle);
BxTaskCreate(vTaskFunction, "Task", 1000, NULL, 1);
CxTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xHandle);
DxTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, xHandle);
Attempts:
2 left
💡 Hint
Check the type of the second argument in xTaskCreate.
🚀 Application
expert
2: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?
A22
B20
C24
D26
Attempts:
2 left
💡 Hint
Calculate available memory and divide by total memory per task (stack + TCB).