0
0
FreeRTOSprogramming~20 mins

Task states (Ready, Running, Blocked, Suspended) in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Task State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS task state check?

Consider a FreeRTOS task that is created and immediately started. The task then calls vTaskDelay() for 100 ticks. What will be the task state right after vTaskDelay() is called?

FreeRTOS
TaskHandle_t xTask;

void vTaskFunction(void *pvParameters) {
    // Task runs
    vTaskDelay(100);
    // Task resumes here
    for(;;) {}
}

int main() {
    xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xTask);
    vTaskStartScheduler();
    // After scheduler starts, what is the state of xTask immediately after vTaskDelay call?
}
ARunning
BReady
CBlocked
DSuspended
Attempts:
2 left
💡 Hint

Think about what vTaskDelay() does to the task state.

🧠 Conceptual
intermediate
1:30remaining
Which task state allows a task to be selected by the scheduler to run?

In FreeRTOS, which task state means the task is ready and waiting for CPU time?

AReady
BSuspended
CBlocked
DDeleted
Attempts:
2 left
💡 Hint

Think about which state means the task can run but is waiting for the CPU.

Predict Output
advanced
2:00remaining
What happens if a task is suspended and then resumed?

Given a task that is suspended using vTaskSuspend() and later resumed with vTaskResume(), what is the task state immediately after resuming?

FreeRTOS
TaskHandle_t xTask;

void vTaskFunction(void *pvParameters) {
    for(;;) {
        // Task code
    }
}

int main() {
    xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xTask);
    vTaskStartScheduler();
    vTaskSuspend(xTask);
    // Task is suspended here
    vTaskResume(xTask);
    // What is the state now?
}
ARunning
BReady
CSuspended
DBlocked
Attempts:
2 left
💡 Hint

Resuming a suspended task makes it available to run again.

🔧 Debug
advanced
2:30remaining
Why does this task never run after creation?

Examine the code below. The task is created but never runs. What is the reason?

FreeRTOS
TaskHandle_t xTask;

void vTaskFunction(void *pvParameters) {
    for(;;) {
        // Task code
    }
}

int main() {
    xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xTask);
    // Missing vTaskStartScheduler();
    // What is the task state?
}
AThe task is in Ready state but scheduler is not started, so it never runs.
BThe task is Suspended because it was not started properly.
CThe task is Blocked because it waits for an event.
DThe task is Deleted immediately after creation.
Attempts:
2 left
💡 Hint

Think about what starts the FreeRTOS scheduler.

🧠 Conceptual
expert
3:00remaining
How does FreeRTOS handle a task that is both blocked and suspended?

If a task is in the Blocked state waiting for a delay to expire, and then vTaskSuspend() is called on it, what is the task state?

AThe task remains Blocked until the delay expires, then moves to Suspended.
BThe task is Deleted automatically.
CThe task moves to Ready state immediately.
DThe task immediately moves to Suspended, ignoring the delay.
Attempts:
2 left
💡 Hint

Suspending a task overrides other states.