CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    105

    Question Idle for some microseconds without occupying CPU time?

    Is there such a function that idles the program for some specified number of microseconds but does not consume CPU time? I use a loop and gettimeofday() but that keeps the CPU from doing other things. Thanks!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Idle for some microseconds without occupying CPU time?

    On Windows, there's Sleep(). However, you cannot guarantee exactly when that will return because Windows is not a real-time OS---it only promises to relinquish control for at least the specified number of milliseconds.

    In practice, you'll probably see about 10ms as the mimimum sleep time.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Idle for some microseconds without occupying CPU time?

    sleep(milliseconds)

    It's not standard as far as I know, but all POSIX based systems (most UNIX and Linux) support it.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Idle for some microseconds without occupying CPU time?

    You're probably looking for something like sleep or Sleep.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Nov 2010
    Posts
    105

    Re: Idle for some microseconds without occupying CPU time?

    Thank you all!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured