Bird
Raised Fist0
Embedded Cprogramming~20 mins

Bare-metal vs RTOS execution model in Embedded C - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Embedded Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of bare-metal loop execution
Consider this bare-metal style embedded C code running on a microcontroller. What will be the output on the serial console?
Embedded C
#include <stdio.h>

int main() {
    int count = 0;
    while (count < 3) {
        printf("Tick %d\n", count);
        count++;
    }
    return 0;
}
ATick 0\nTick 1\nTick 2\nTick 3\n
BTick 1\nTick 2\nTick 3\n
CTick 0\nTick 1\nTick 2\n
DNo output, infinite loop
Attempts:
2 left
💡 Hint
Count starts at 0 and increments until it reaches 3, but loop stops before printing count 3.
❓ Predict Output
intermediate
2:00remaining
RTOS task scheduling output
Given this simplified RTOS task code, what is the output order on the console?
Embedded C
#include <stdio.h>
#include <unistd.h>

void task1() {
    printf("Task 1 start\n");
    sleep(1);
    printf("Task 1 end\n");
}

void task2() {
    printf("Task 2 start\n");
    sleep(1);
    printf("Task 2 end\n");
}

int main() {
    task1();
    task2();
    return 0;
}
ATask 1 start\nTask 2 start\nTask 1 end\nTask 2 end\n
BTask 1 start\nTask 1 end\nTask 2 start\nTask 2 end\n
CTask 2 start\nTask 2 end\nTask 1 start\nTask 1 end\n
DTask 1 start\nTask 2 start\nTask 2 end\nTask 1 end\n
Attempts:
2 left
💡 Hint
Tasks run one after another in this code, no real multitasking.
🧠 Conceptual
advanced
2:00remaining
Difference in execution models
Which statement best describes the difference between bare-metal and RTOS execution models?
ABare-metal supports multitasking natively; RTOS runs only one task at a time.
BBare-metal uses threads; RTOS uses only interrupts.
CBare-metal requires an OS kernel; RTOS runs without any kernel.
DBare-metal runs a single loop without preemption; RTOS supports multiple tasks with preemptive scheduling.
Attempts:
2 left
💡 Hint
Think about how tasks are managed and switched.
🔧 Debug
advanced
2:00remaining
Identify the RTOS scheduling bug
This RTOS task code is intended to print alternating messages from two tasks. What is the bug causing only one task to print repeatedly?
Embedded C
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void* task1(void* arg) {
    while(1) {
        printf("Task 1 running\n");
        sleep(1);
    }
    return NULL;
}

void* task2(void* arg) {
    while(1) {
        printf("Task 2 running\n");
        sleep(1);
    }
    return NULL;
}

int main() {
    pthread_t t1, t2;
    pthread_create(&t1, NULL, task1, NULL);
    pthread_join(t1, NULL);
    pthread_create(&t2, NULL, task2, NULL);
    pthread_join(t2, NULL);
    return 0;
}
AThe program blocks on pthread_join(t1), so task2 never runs.
BThe sleep(1) calls cause the tasks to never yield CPU.
CThe tasks lack a termination condition causing deadlock.
Dpthread_create is called incorrectly without task priorities.
Attempts:
2 left
💡 Hint
Check what happens after pthread_join(t1) is called.
🚀 Application
expert
3:00remaining
Choosing execution model for a real-time sensor system
You design a sensor system that must read data every 10ms and process it without delay. Which execution model is best and why?
ABare-metal, because it has minimal overhead and predictable timing.
BRTOS, because it allows multitasking and dynamic memory allocation.
CBare-metal, because it supports preemptive multitasking natively.
DRTOS, because it eliminates the need for interrupts.
Attempts:
2 left
💡 Hint
Consider timing predictability and overhead.

Practice

(1/5)
1. Which statement best describes the bare-metal execution model in embedded C?
easy
A. Multiple tasks run concurrently with a scheduler.
B. It requires an operating system to manage tasks.
C. Code runs directly on hardware with a single main loop.
D. It uses virtual machines to isolate processes.

Solution

  1. Step 1: Understand bare-metal execution

    Bare-metal means the program runs directly on the hardware without an operating system.
  2. Step 2: Identify the execution style

    Bare-metal typically uses a single main loop to control the program flow.
  3. Final Answer:

    Code runs directly on hardware with a single main loop. -> Option C
  4. Quick Check:

    Bare-metal = single main loop [OK]
Hint: Bare-metal means one main loop, no OS multitasking [OK]
Common Mistakes:
  • Confusing bare-metal with RTOS multitasking
  • Thinking bare-metal requires an OS
  • Assuming bare-metal uses task scheduling
2. Which of the following is the correct way to start a task in an RTOS environment in embedded C?
easy
A. void startTask() { while(1) { /* task code */ } }
B. xTaskCreate(taskFunction, "Task", 1000, NULL, 1, NULL);
C. main() { runTask(); }
D. createThread(taskFunction);

Solution

  1. Step 1: Recognize RTOS task creation syntax

    In embedded C with RTOS like FreeRTOS, tasks are created using xTaskCreate().
  2. Step 2: Match the correct function call

    xTaskCreate(taskFunction, "Task", 1000, NULL, 1, NULL); uses xTaskCreate() with proper parameters to start a task.
  3. Final Answer:

    xTaskCreate(taskFunction, "Task", 1000, NULL, 1, NULL); -> Option B
  4. Quick Check:

    RTOS task start = xTaskCreate() [OK]
Hint: RTOS tasks start with xTaskCreate() function [OK]
Common Mistakes:
  • Using infinite loops without RTOS task creation
  • Calling non-existent functions like createThread()
  • Starting tasks directly in main() without scheduler
3. Given the following code snippet in a bare-metal system:
int main() {
  while(1) {
    toggleLED();
  }
  return 0;
}

What will happen when this runs?
medium
A. The LED toggles continuously without stopping.
B. The program creates multiple tasks to toggle the LED.
C. The LED toggles once and the program ends.
D. The program will cause a runtime error.

Solution

  1. Step 1: Analyze the infinite loop

    The while(1) loop runs forever, repeatedly calling toggleLED().
  2. Step 2: Understand bare-metal behavior

    Since there is no OS, the program stays in this loop, toggling the LED continuously.
  3. Final Answer:

    The LED toggles continuously without stopping. -> Option A
  4. Quick Check:

    Infinite loop toggles LED forever [OK]
Hint: Infinite loop means continuous action in bare-metal [OK]
Common Mistakes:
  • Thinking tasks are created automatically
  • Assuming program ends after one toggle
  • Expecting runtime errors without cause
4. In an RTOS program, the following code snippet causes the LED to toggle only once:
void taskLED(void *params) {
  toggleLED();
}

int main() {
  xTaskCreate(taskLED, "LED", 1000, NULL, 1, NULL);
  vTaskStartScheduler();
  while(1) {}
}

What is the main problem?
medium
A. The task function lacks an infinite loop to keep running.
B. The scheduler is not started properly.
C. The task priority is too low to run.
D. The LED toggle function is incorrect.

Solution

  1. Step 1: Check the task function structure

    The task function runs toggleLED() once and then returns, ending the task immediately.
  2. Step 2: Understand RTOS task lifetime

    RTOS tasks must have an infinite loop to keep running and performing actions repeatedly.
  3. Final Answer:

    The task function lacks an infinite loop to keep running. -> Option A
  4. Quick Check:

    RTOS tasks need infinite loops [OK]
Hint: RTOS tasks must loop forever to keep running [OK]
Common Mistakes:
  • Forgetting infinite loop in task function
  • Assuming scheduler auto-repeats tasks
  • Blaming LED function without checking task code
5. You have a project that needs to read sensor data, control motors, and communicate over UART simultaneously. Which execution model is best and why?
hard
A. Bare-metal, because it is simpler and uses one main loop.
B. Bare-metal, because multitasking is not possible in RTOS.
C. RTOS, but only if the hardware supports virtual machines.
D. RTOS, because it can run multiple tasks concurrently with scheduling.

Solution

  1. Step 1: Analyze project requirements

    The project needs to handle sensor reading, motor control, and UART communication at the same time.
  2. Step 2: Match execution model to multitasking needs

    RTOS supports multiple tasks running concurrently with a scheduler, ideal for complex multitasking.
  3. Final Answer:

    RTOS, because it can run multiple tasks concurrently with scheduling. -> Option D
  4. Quick Check:

    Multitasking needs = RTOS [OK]
Hint: Use RTOS for multitasking, bare-metal for simple loops [OK]
Common Mistakes:
  • Choosing bare-metal for complex multitasking
  • Thinking RTOS can't multitask
  • Confusing virtual machines with RTOS requirements
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