From: jklowden@speakeasy.net   
      
   On Mon, 24 Sep 2012 12:20:31 CST   
   fmatthew5876 wrote:   
      
   > > Before answering you specific question, I would comment that I would   
   > > try to avoid polling.   
   > >   
   > In almost any other application I would agree. However in a game   
   > that runs its main loop 60 times per second, I think polling to see   
   > if the IO is done each frame makes sense.   
      
   Why? Machines are fast and people are slow. Even *video* is slow if   
   you're talking about refresh rates.   
      
   A pretty slow processor these days executes a billion or so cycles per   
   second, and instructions take under 100 cycles. A 100-cycle   
   instruction called 100 times a second would use less than 0.001% of   
   the processor's capacity.   
      
   In "The Linux Programming Interface", Michael Kerrisk talks about   
   getpid(2), something *much* heavier weight than blocking on a thread:   
      
    "On one of the author?s x86-32 systems running Linux 2.6.25,   
   10 million calls to getppid() required approximately 2.2 seconds to   
   complete. This amounts to around 0.3 microseconds per call. By   
   comparison, on the same system, 10 million calls to a C function that   
   simply returns an integer required 0.11 seconds, or around   
   one-twentieth of the time required for calls to getppid()."   
      
   IOW he could call getpid 75,000 times in 1/60 of a second. Give or   
   take an order of magnitude, you probably can, too.   
      
   --jkl   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|