This was meant to be a general question independent of language but never the less I chose to post it here: I've always wandered what does the CPU do when a program reaches a line that contains Delay() or in general a command that sleeps the current thread it is on. For example if I wrote an infinite while loop in the main thread and executed the program it would eat all the CPU time for that particular core it is running on (25% of the processor for me) . However if I added a Delay(50) , what does the CPU do during those 50ms ? Does it know that in the current thread that it has found this delay it should give time back to the OS to do other things or start processing another thread instead ? Is this why some code examples contain Delay() commands in them?
Thanks
What happens when Delay() is processed
Re: What happens when Delay() is processed
Delay() is not a CPU/ASM command, it is an OS function. It tells the OS that it should not switch to your
thread for a certain amount of time. The OS Task Scheduler switches to other processes in the meantime.
When the OS itself has nothing to do, it can tell the CPU so, for example with HLT instruction, to enter Idle state.
thread for a certain amount of time. The OS Task Scheduler switches to other processes in the meantime.
When the OS itself has nothing to do, it can tell the CPU so, for example with HLT instruction, to enter Idle state.
Re: What happens when Delay() is processed
Interesting!Danilo wrote:Delay() is not a CPU/ASM command, it is an OS function. It tells the OS that it should not switch to your
thread for a certain amount of time. The OS Task Scheduler switches to other processes in the meantime.
When the OS itself has nothing to do, it can tell the CPU so, for example with HLT instruction, to enter Idle state.
thank's

- Teddy Rogers
- User
- Posts: 98
- Joined: Sun Feb 23, 2014 2:05 am
- Location: Australia
- Contact:
Re: What happens when Delay() is processed
Delay is a rebadged version of the Windows API Sleep function...
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Ted.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Ted.