|
Wait Functions
The Win32 API provides a set of wait functions to allow a thread to block its own execution. There are three types of wait
functions:
- single-object
- multiple-object
- alertable
The wait functions do not return until the specified criteria have been met.
The type of wait function determines the set of criteria used. When a wait
function is called, it checks whether the wait criteria have been met. If the
criteria have not been met, the calling thread enters an efficient wait state,
consuming very little processor time while waiting for the criteria to be met.
Single-object Wait Functions
The SignalObjectAndWait, WaitForSingleObject, and WaitForSingleObjectEx functions require a handle of one synchronization object. These functions
return when one of the following occurs:
- The specified object is in the signaled state.
- The time-out interval elapses. The time-out interval can be set to INFINITE to
specify that the wait will not time out.
The SignalObjectAndWait function enables the calling thread to atomically set the state of an object
to signaled and wait for the state of another object to be set to signaled.
Multiple-object Wait Functions
The WaitForMultipleObjects, WaitForMultipleObjectsEx, MsgWaitForMultipleObjects, and MsgWaitForMultipleObjectsEx functions enable the calling thread to specify an array containing one or
more synchronization object handles. These functions return when one of the
following occurs:
- The state of any one of the specified objects is set to signaled or the states
of all objects have been set to signaled. You control whether one or all of
the states will be used in the function call.
- The time-out interval elapses. The time-out interval can be set to INFINITE to
specify that the wait will not time out.
The MsgWaitForMultipleObjects and MsgWaitForMultipleObjectsEx function allow you to specify input event objects in the object handle array.
This is done when you specify the type of input to wait for in the thread's
input queue.
For example, a thread could use MsgWaitForMultipleObjects to block its execution until the state of a specified object has been set to
signaled and there is mouse input available in the thread's input queue. The
thread can use the GetMessage or PeekMessage function to retrieve the input.
When waiting for the states of all objects to be set to signaled, these
multiple-object functions do not modify the states of the specified objects until the
states of all objects have been set signaled. For example, the state of a
mutex object can be signaled, but the calling thread does not get ownership until
the states of the other objects specified in the array have also been set to
signaled. In the meantime, some other thread may get ownership of the mutex
object, thereby setting its state to nonsignaled.
Alertable Wait Functions
The MsgWaitForMultipleObjectsEx, SignalObjectAndWait, WaitForMultipleObjectsEx, and WaitForSingleObjectEx functions differ from the other wait functions in that they can optionally
perform an alertable wait operation. In an alertable wait operation, the function can return when the specified
conditions are met, but it can also return if the system queues an I/O
completion routine or an APC for execution by the waiting thread. For more information
about alertable wait operations and I/O completion routines, see Synchronization and Overlapped Input and Output. For more information about APCs, see Asynchronous Procedure Calls.
Wait Functions and Synchronization Objects
Before returning, a wait function can modify the states of some types of synchronization objects. Modification occurs only for the object or objects whose signaled state
caused the function to return. A wait function can modify the states of
synchronization objects as follows:
- The count of a semaphore object decreases by one, and the state of the
semaphore is set to nonsignaled if its count is zero.
- The states of mutex, auto-reset event, and change-notification objects are set
to nonsignaled.
- The state of a synchronization timer is set to nonsignaled.
- The states of manual-reset event, manual-reset timer, process, thread, and
console input objects are not affected by a wait function.
Wait Functions and DDE
You have to be careful when using the wait functions and DDE. If a thread
creates any windows, it must process messages. DDE sends messages to all windows in
the system. If you have a thread that uses a wait function with no time-out
interval, the system will deadlock. Therefore, if you have a thread that creates
windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than the other wait functions.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|