Suppose I have some code that does this:
while(1) {
scanf("%c", &key);
// if E or e, exit
if (key == 'E' || key == 'e')
break;
}
This obviously does not take up all the resources of even a single core. It just... "sits" there until someone actually presses an E. My question is: how does the runtime find out that it should not take up all the resources of a core just waiting for a scanf? Is scanf a special case in that it is I/O and as such the OS schedules it out until a key is effectively pressed? Can I somehow force it to be while
ing all the time by say, adding a a++
inside the loop?