double Sleep(rand()%0.1);

This is a discussion on double Sleep(rand()%0.1); within the C++ Programming forums, part of the General Programming Boards category; That seems illogical, at least on Windows since threads aren't scheduled that way. Threads are dynamically assigned time slices depending ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,999
    That seems illogical, at least on Windows since threads aren't scheduled that way.
    Threads are dynamically assigned time slices depending on remaining time over from higher threads. There's just no way it will be able to call back in the specified time unless the thread has a time slice.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think Elysia is on the right track. A "timer callback" will not be issued until it's time to schedule the thread. If your thread is higher priority than the currently running one, then it will happen immediately as the kernel reschedules [which is part of the returning from an interrupt].

    I just found this function: timeBeginPeriod()
    http://msdn2.microsoft.com/en-us/library/ms713413.aspx

    It appears that you can change the timer behaviour in Windows with this call.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,999
    I believe the timer allows the kernel to reschedule threads every X ms specified, if I understand it correctly. However, you can't force it to reschedule on periods less than 1 ms. So it still won't allow you "sleep" half a millisecond or so.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    I believe the timer allows the kernel to reschedule threads every X ms specified, if I understand it correctly. However, you can't force it to reschedule on periods less than 1 ms. So it still won't allow you "sleep" half a millisecond or so.
    No, and it would be terribly inefficient to run the scheduler [even if it doesn't reschedule, it still has to update the stats for each process] 2000 times a second, don't you think?

    I also believ the DEFAULT timer tick is 10ms, so you get 10x better precision.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 04:44 PM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 03:54 PM
  3. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 09:54 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21