O'Reilly logo

Shared Source CLI Essentials by Ted Neward, Geoff Shilling, David Stutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Signaling

The PAL provides a number of waiting functions for threads. All of these (WaitForSingleObject, WaitForMultipleObjects, Sleep, and SleepEx) are implemented using WaitForMultipleObjectsEx . Because of this, this section will step through only WaitForMultipleObjectsEx. You will understand how signal waiting is done in the PAL if you understand how this function, defined in pal/unix/sync/wait.c, works.

Warning

The code for WaitForMultipleObjectsEx can be tricky to trace at runtime, due to its use of indirect recursion, as well as its use of a worker thread when waiting for a process to terminate.

Here is the function prototype for WaitForMultipleObjectsEx:

    WaitForMultipleObjectsEx(
           IN DWORD nCount,
           IN CONST HANDLE *lpHandles,
           IN BOOL bWaitAll,
           IN DWORD dwMilliseconds,
           IN BOOL bAlertable)

The arguments lpHandles and nCount combine to specify an array containing the handles of all objects to wait on. If all objects must signal before the function returns, bWaitAll is set to true; otherwise, the first object to signal will cause the function to return. The dwMilliseconds argument is used to indicate how long a timeout to use before returning, regardless of success. This argument may be INFINITE, in which case the wait will return only when all wait conditions have been met. Finally, bAlertable indicates that the wait may be terminated by a queued APC, which is discussed in the later section "Asynchronous Procedure Calls.”

The first thing done in WaitForMultipleObjectsEx ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required