locked
usleep

    Question

  •  

    Is there a way to suspend the active thread for 1.6 msec? I mean I cannot use sleep, intstead I would like to use something like the linux's usleep.

    I'd really appreciate if someone can help me.

     

    Best regards and thans in advance,

     

    Javier.

     

    Saturday, August 23, 2008 6:12 PM

Answers

  • There is no way you can suspend anything in Windows with that accuracy. Even if you just release the thread and immediately put it in the active queue again by means of Sleep(0), it may easily take 50 mS or more before the thread gets the control back because there may be more threads waiting in the queue.

     

    Thread switching is usually done every 10 mS in a single core system and every 15 mS in case of a multicore CPU so forget everything about an accuracy better than 50-100 mS.

    Sunday, August 24, 2008 10:24 AM

All replies

  • There is no way you can suspend anything in Windows with that accuracy. Even if you just release the thread and immediately put it in the active queue again by means of Sleep(0), it may easily take 50 mS or more before the thread gets the control back because there may be more threads waiting in the queue.

     

    Thread switching is usually done every 10 mS in a single core system and every 15 mS in case of a multicore CPU so forget everything about an accuracy better than 50-100 mS.

    Sunday, August 24, 2008 10:24 AM
  • Maybe you could try a select( ) call on an unused port. select is a blocking function that takes in a delay with us precision. There isn't going to be any activity on this port since it is unused, and it waits for the desired amount of time. This should work despite the issues pointed out previously by Carsten if you are using only one thread.

    Monday, November 24, 2008 10:25 PM