Unix to Windows Porting Dictionary for HPC |
||
|
|
||
|
|
LinksFunction List
|
Table of Contents header file: winbase.h
HANDLE WINAPI CreateEvent(
__in_opt LPSECURITY_ATTRIBUTES lpEventAttributes,
__in BOOL bManualReset,
__in BOOL bInitialState,
__in_opt LPCTSTR lpName
);
DWORD WINAPI WaitForSingleObject(
__in HANDLE hHandle,
__in DWORD dwMilliseconds
);
BOOL WINAPI SetEvent(
__in HANDLE hEvent
);
The pause() function forces a process to wait until a Unix signal has been sent to the process. One of the most significant paradigm differences between Unix and Windows is the use of signals. Unix systems use signals as a means to alerting a process to a special event. There are numerous different signals with most having standard meanings that provide a context for how the program will react. Signals on Unix systems can interrupt the normal flow of a program and are usually given immediate priority. Windows programs can detect when certain events happen. However, the raising of an event is not delivered to a program directly as on Unix. Instead the program must already be waiting to detect the event. If a Windows program is not waiting for an event then it can never know that another program that it has no knowledge about wants to alert it. A general equivalent to the pause() function does not exist with Windows because of the paradigm differences. Therefore a complete examination of why the pause() function is being used is required to determine what course of action can be taken. There are some Unix signals that can be emulated on a case by case basis. The receipt of the SIGCHLD signal can be emulated as described with the waitpid() dictionary entry. In some cases the pause() function is used as a gate-keeper to allow the program to continue after being signaled for a special circumstance. The code might be modified to use Windows events. This will mean both the sending and the receiving programs must use an event they both know about. The Windows CreateEvent() function may be used for this circumstance along with the Windows WaitForSingleObject() or WaitForMultipleObjects() functions. Example 1
DWORD rez;
HANDLE h;
h = CreateEvent(NULL, TRUE, FALSE, "OurSpecialEvent");
rez = WaitForSingleObject(h, INFINITE);
Example 2 BOOL ans; HANDLE h; h = CreateEvent(NULL, TRUE, FALSE, "OurSpecialEvent"); ans = SetEvent(h); |