HeapCrash / Challenges / Critical sections and scheduler locks

Critical sections and scheduler locks

g_stats is updated by an ADC interrupt. configTICK_RATE_HZ is 100. Saving the config makes UART input drop characters.

RTOSMedium4 bugs~5 minRTOS and concurrency

The code

Embedded C for Cortex-M. It compiles. There are 4 real bugs in it: the kind that pass a bench test and fail in the field.

void update_config(const config_t *c)
{
    taskENTER_CRITICAL();
    memcpy(&g_cfg, c, sizeof g_cfg);
    flash_save(&g_cfg);
    taskEXIT_CRITICAL();
}

void stats_task(void *p)
{
    for (;;) {
        vTaskSuspendAll();
        uint32_t n   = g_stats.count;
        float    avg = g_stats.sum / n;
        xTaskResumeAll();
        printf("avg %.2f\n", avg);
        vTaskDelay(1000);
    }
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs