CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    42

    To boldy go were no thread has gone before

    Hi there folks!

    The SleepEx() system call can be used to suspend a thread. One parameter is a timeout value, specified in milliseconds.

    However the resolution of this timeout seems to be about 10ms and I have to go beyond that.

    I've tried SleepEx( 0, FALSE ) but than the thread just yields and will become active with no timeout.

    Does anyone know a way to yield processor time with a higher resolution.


    Thanks!

    Martin van den Berg
    High Tech Automation
    The Netherlands
    [email protected]

  2. #2
    Join Date
    May 1999
    Location
    Sweden
    Posts
    10

    Re: To boldy go were no thread has gone before

    As far as I know all operating systems have some timeslice it uses. There is no point in having shorter time slices because then the overhead from switching processes/threads would be so great that the thread/process would not be able to do any work.

    Now, you have found that 10ms seams to be the "timeslice" for your computer. Seams resonable to me. And there is probably nothing you can do about it. But when you call SleepEx(0,FALSE) (according to MSDN documentation) you'll force a probable thread/process switch. If there is no other thread/process with the same priority, your thread will not "sleep".

    So the question is, why should the thread sleep? To let other threads have a go or to delay execution for some time? SleepEx(0,FALSE) is good enough if you just want other threads to have a chance to execute, but if you really want that delay, then you're stuck with the 10ms I guess...

    From MSDN (about SleepEx first parameter):
    "A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. "

    ---------------------------------------------
    Emil Gustafsson
    M.Sc. Computer Science
    NTier Solutions AB
    [email protected]

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