Page 1 of 1
					
				What happens when Delay() is processed
				Posted: Tue May 27, 2014 5:52 pm
				by Nubcake
				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
			 
			
					
				Re: What happens when Delay() is processed
				Posted: Tue May 27, 2014 6:38 pm
				by Danilo
				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.
 
			 
			
					
				Re: What happens when Delay() is processed
				Posted: Tue May 27, 2014 8:35 pm
				by Otrebor
				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.
 
Interesting!
thank's 

 
			 
			
					
				Re: What happens when Delay() is processed
				Posted: Wed May 28, 2014 2:43 pm
				by Teddy Rogers
				Delay is a rebadged version of the Windows API Sleep function...
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Ted.