Questions about task scheduling

as soon as you sleep the task yields

I feel like this is extremely dangerous on a singlecore system. An example:

vpTask1(void)
{
    fprintf(stdout, "Task 1 - a\n");
    usleep(1); //allow task 1 - implicit yield
    fprintf(stdout, "Task 1 - b\n");
}

vpTask2(void)
{
    fprintf(stdout, "Task 2\n");
    while(1); // Task 2 blocks here (eg due to a bug) and never allows task 1 to ever run again
}

I think that if eg task1 just uses a sleep in order to allow external hardware to send data or do something (and doesn't use any interrupt mechanism), you allow task2 to do stuff and accidentally never allow task1 to ever run again.

/r/embedded Thread Parent