Jump to content

  • Log In with Google      Sign In   
  • Create Account


Idov

Member Since 30 Nov 2006
Offline Last Active Sep 28 2013 06:58 AM

Posts I've Made

In Topic: Making a "Busy Loop" not consume that much CPU (without Sleep)

19 May 2013 - 02:32 PM

Hi,
I tried using Waitable Timers like in this example:
http://msdn.microsoft.com/en-us/library/ms687008.aspx

But it seems that the event is signaled only after 1 milisecond and after not the time I specified...
I tried using:
   double timeoutMicro = 400;
    liDueTime.QuadPart =  -1 * timeoutMicro * 10;
 


In Topic: Making a "Busy Loop" not consume that much CPU (without Sleep)

19 May 2013 - 10:10 AM

@Hodgman & galop1n:
I'm trying to sample another process (memory, stack, etc) and I'm checking the boundaries of what I can and cannot do (without using all the resources of the computer). :)
 


In Topic: Making a "Busy Loop" not consume that much CPU (without Sleep)

18 May 2013 - 12:17 PM

 VildNinja:

As far as I know you will not get the desired effect from the loop, since most system timers are no more precise than ~10 ms, even though you can get the number represented in nanoseconds. So unless you are using a method to get a very accurate time, you might as well use sleep.

 

I'm using QueryPerformanceCounter in order to measure time in a higher resolution. :)


CornStalks:

That's true, yielding typically only helps if other threads are available for running. But remember, on modern computers there are often hundreds of threads in existence, and the OS can idle the CPU in its own threads if there isn't work to be done (so the OS threads can potentially eat the remaning time with proper CPU idling). I recall a few times I had a program doing a loop that went from about 100% CPU usage to near 0% usage after putting a single yield in it (I don't recall the exact amount it dropped by, but it was significant).

 

I just tried using Sleep(0). It didn't have any effect :/


Frob:

One of the bester options for a short wait is to use the WaitableTimer object. It can be set in (approximately) 200 nanosecond increments, then use WaitForSingleObject (or similar) to wait for it to trigger. There is more on MSDN. Be sure to pass a NEGATIVE time value so it knows the value is relative, otherwise you'll be setting timers that trigger back in the year 1600 or so.


I will sure try it, but how is it possible?
I've always been told that windows is not a RT system and it can't wait for periods shorter than 1 ms... Is it wrong?

 


In Topic: Making a "Busy Loop" not consume that much CPU (without Sleep)

18 May 2013 - 11:22 AM

Ok, thanks!
But as far as I understand Sleep(0), SwitchToThread, etc. will only switch to another thread if there is another thread waiting to use the CPU, but if there isn't one - it won't do anything.
 

I will try to use it, but what do you say about using functions such as printf() that uses the IO devices and not the CPU in order to achieve my goal? 


In Topic: Finding out which x64 instruction the IP points at

19 April 2013 - 03:08 PM

oops,  thanks :)
Is there a place where I can see a list of the op codes for x64 (or how the op code are structured)?
I think it will be much more easy and "safe" than to look for what I need in random assembly code...


PARTNERS