sleep() blocks the running thread in C given x amount of seconds.
If I'm not mistaking, this can be implemented in 2 ways. Either go in an infinite loop and check the current time with BIOS, if time>=timeout then end the loop.
Second way is to use a timer in CPU and let the timer do the counting async and not block the CPU thread.
Am I correct about the above 2 methods? if so why doesn't C have a function to implant the second way so we can have non-blocking "delays"?
sleepcould have had anasyncversion a swell right? nothing is stopping the hardware from doing it.sleep()which blocks the program (or thread) but hopefully doesn't block the CPU (so that other threads or processes can run), and asynchronous timers like the non-ISOalarm()that let the program keep running and notify it after a certain length of time. It is entirely possible for the OS to implementsleepin your "second way" without a busy loop, by switching to another process (or halting the CPU) and letting a timer interrupt cause a switch back when the timeout expires.