vendredi 8 mai 2015

Timer to implement a time-out function

I'm writing a Windows (Win32) program in C, which features a worker thread to process data from a USB hardware device. The thread handling all works well, however I now need to add a timer to handle a timeout function. I don't need a callback function, just the ability to start a single shot timer, and to be able to test weather it's complete without sleeping, something like this:

start_timout(1000);   // 1 second

while (timer_is_running())
{
  doing stuff while waiting...
  .
  .
  .
}

do stuff after timer is finished...
.
.
.

This would be running inside the worker thread.

I've looked at SetTimer(), and have tried creating a callback function that simply sets a global flag, then test for the flag, but that never gets set. I'm not sure if this is because I don't have a message handler inside my thread.

Any suggestions welcome.. Cheers!

Aucun commentaire:

Enregistrer un commentaire