Bird
Raised Fist0
FreeRTOSprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1.

Which FreeRTOS task state means the task is waiting to be assigned CPU time but is ready to run?

easy
A. Suspended
B. Running
C. Blocked
D. Ready

Solution

  1. Step 1: Understand the meaning of Ready state

    The Ready state means the task is prepared and waiting for CPU time but is not currently running.
  2. Step 2: Compare with other states

    Running means the task is currently executing. Blocked means waiting for an event. Suspended means paused by user.
  3. Final Answer:

    Ready -> Option D
  4. Quick Check:

    Ready = waiting to run [OK]
Hint: Ready means waiting but able to run soon [OK]
Common Mistakes:
  • Confusing Ready with Running
  • Thinking Blocked means ready
  • Mixing Suspended with Blocked
2.

Which of the following is the correct way to suspend a task in FreeRTOS?

void suspendTask(TaskHandle_t task) {
    // What function to call?
}
easy
A. vTaskBlock(task);
B. vTaskSuspend(task);
C. vTaskReady(task);
D. vTaskRun(task);

Solution

  1. Step 1: Recall FreeRTOS API for suspending tasks

    The function to suspend a task is vTaskSuspend(), which pauses the task until resumed.
  2. Step 2: Verify other options

    vTaskBlock() and vTaskReady() do not exist as API calls. vTaskRun() is not a FreeRTOS function.
  3. Final Answer:

    vTaskSuspend(task); -> Option B
  4. Quick Check:

    Suspend task = vTaskSuspend() [OK]
Hint: Suspend tasks with vTaskSuspend() function [OK]
Common Mistakes:
  • Using non-existent functions
  • Confusing suspend with block
  • Trying to run tasks manually
3.

Consider this FreeRTOS code snippet:

void vTaskFunction(void *pvParameters) {
    for (;;) {
        if (xSemaphoreTake(xSemaphore, 0) == pdTRUE) {
            // Critical section
        } else {
            vTaskDelay(pdMS_TO_TICKS(100));
        }
    }
}

What is the state of the task when vTaskDelay() is called?

medium
A. Running
B. Ready
C. Blocked
D. Suspended

Solution

  1. Step 1: Understand vTaskDelay effect

    Calling vTaskDelay causes the task to enter Blocked state, waiting for the delay time to expire.
  2. Step 2: Confirm task state during delay

    While delayed, the task is not Ready or Running; it is Blocked until the timer expires.
  3. Final Answer:

    Blocked -> Option C
  4. Quick Check:

    vTaskDelay = Blocked state [OK]
Hint: vTaskDelay puts task in Blocked state [OK]
Common Mistakes:
  • Thinking delay means Ready
  • Confusing Blocked with Suspended
  • Assuming task runs during delay
4.

Identify the error in this FreeRTOS task management code:

vTaskSuspend(NULL);
vTaskResume(NULL);
vTaskResume(xTaskHandle);

What is wrong with this code?

medium
A. vTaskResume(NULL) is invalid and causes error
B. Cannot suspend current task with NULL parameter
C. vTaskResume requires task handle, NULL is allowed
D. No errors, code is correct

Solution

  1. Step 1: Check vTaskSuspend(NULL) usage

    Passing NULL to vTaskSuspend suspends the current task, which is valid.
  2. Step 2: Check vTaskResume(NULL) usage

    Passing NULL to vTaskResume is invalid and causes an error because NULL is not a valid task handle to resume.
  3. Final Answer:

    vTaskResume(NULL) is invalid and causes error -> Option A
  4. Quick Check:

    vTaskResume(NULL) causes error [OK]
Hint: vTaskResume(NULL) is invalid, must use valid handle [OK]
Common Mistakes:
  • Assuming NULL resumes current task
  • Confusing suspend and resume parameters
  • Ignoring NULL parameter rules
5.

You want to create a task that waits for a button press event without using CPU time unnecessarily. Which task state should the task enter while waiting?

hard
A. Blocked
B. Ready
C. Running
D. Suspended

Solution

  1. Step 1: Understand waiting without CPU use

    To avoid wasting CPU, the task should not be Running or Ready while waiting.
  2. Step 2: Choose appropriate waiting state

    Blocked state is used when a task waits for an event like a button press, so it sleeps until event occurs.
  3. Step 3: Differentiate from Suspended

    Suspended means paused by user, not event-driven waiting.
  4. Final Answer:

    Blocked -> Option A
  5. Quick Check:

    Wait for event = Blocked state [OK]
Hint: Wait for event = Blocked to save CPU [OK]
Common Mistakes:
  • Using Suspended instead of Blocked
  • Keeping task Ready and wasting CPU
  • Confusing Running with waiting
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