0
0
Embedded Cprogramming~20 mins

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

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