Introduction
A Win32 event is a system object that provides for
inter-thread communication which supports two states - signaled and Non-signaled.
- Signaled State - (Active or On) Used by waiting threads to know that they may proceed.
- Non-signaled State - (Not Active or Off) indicates to waiting threads that they must continue to wait.
There are two types of events: manual-reset and
auto-reset.
- Manual-Reset Event
- An explicit call to the Win32 API ResetEvent() must be made to move the event from the signaled to Non-signaled state. The syntax for the ResetEvent is given below:
BOOL WINAPI ResetEvent(HANDLE hEvent);
- A call to the Win32 API SetEvent() is made to move from the Non-signaled state to signaled state.
BOOL WINAPI SetEvent(HANDLE hEvent);
- An Auto-Reset Event
- Moves from the signaled to Non-signaled state automatically without a call to ResetEvent().
- However, a call to SetEvent() must still be made to move to the signaled state.
Create Event Object
Win32 API provides a function called CreateEvent, which
is used to create the event thread synchronization object. The manual or auto
reset event choice is passed to the function as a parameter. The syntax for the
function is given below:
HANDLE WINAPI CreateEvent(
LPSECURITY_ATTRIBUTES
lpEventAttributes,
BOOL
bManualReset,
BOOL
bInitialState,
LPCTSTR lpName
);Event Functions
Event
function
|
Description
|
Creates or opens a named or
unnamed event object.
|
|
Creates or opens a named or
unnamed event object and returns a handle to the object.
|
|
Opens an existing named event
object.
|
|
Sets the specified event object
to the signaled state and then resets it to the nonsignaled state after
releasing the appropriate number of waiting threads.
|
|
Sets the specified event object
to the nonsignaled state.
|
|
Sets the specified event object
to the signaled state.
|
Wait Functions
Wait function
|
Description
|
Waits until one or all of the
specified objects are in the signaled state or the time-out interval elapses.
The objects can include input event objects.
|
|
Waits until one or all of the
specified objects are in the signaled state, an I/O completion routine or
asynchronous procedure call (APC) is queued to the thread, or the time-out
interval elapses. The array of objects can include input event objects.
|
|
Directs a wait thread in the thread
pool to wait on the object.
|
|
Signals one object and waits on
another object as a single operation.
|
|
Cancels a registered wait operation.
|
|
Cancels a registered wait operation.
|
|
Waits until one or all of the
specified objects are in the signaled state or the time-out interval elapses.
|
|
Waits until one or all of the
specified objects are in the signaled state, an I/O completion routine or
asynchronous procedure call (APC) is queued to the thread, or the time-out
interval elapses.
|
|
Waits until the specified object is
in the signaled state or the time-out interval elapses.
|
|
Waits until the specified object is
in the signaled state, an I/O completion routine or asynchronous procedure
call (APC) is queued to the thread, or the time-out interval elapses.
|
|
Waits for the value at the specified
address to change.
|
|
An application-defined function that
serves as the starting address for a timer callback or a registered wait
callback.
|
|
Wakes all threads waiting for the
value of an address to change.
|
|
Wakes a thread waiting for the value
of an address to change.
|