Unix to Windows Porting Dictionary for HPC |
||
|
|
||
|
|
LinksFunction List
|
Table of Contents header file: unistd.h unsigned int alarm (unsigned int seconds); int setitimer (int which, struct itimerval *value, struct itimerval *ovalue); The Unix API's alarm() and setitimer() allow for a timer to be set that will send the signal SIGALRM to the Unix process. The Unix process will have earlier set a function to be called when the SIGALRM arrives. That function is required to deal with whatever action needs performing. Windows systems do not have signals and there is a distinct paradigm difference between Unix and Windows. The Windows paradigm makes use of worker threads more. For handling timing events, the Windows paradigm leans towards having a separate worker thread responsible for one or more timing events. The worker thread may spend the vast majority of time idle thus consuming very few resources. However, you may also structure an event loop that periodically checks the status of the timed event to see if it has happened. When using a worker thread to handle the timed event remember that mutexes (locking) may be required in all threads of a program (including the main thread). You may use the Sleep(), WaitForSingleObject() or WaitForMultipleObjects() API's . The WaitForMultipleObjects() will allow the thread to be woken for more than one reason.
int timeout = 10000; // ten second timeout
int rez;
rez = WaitForSingleObject( hExitEvent, timeout );
if (rez == WAIT_OBJECT_0 ) {
return 0; // hExitEvent raised by another thread to exit
}
else {
// Actions to take when the timeout is activated.
}
|