ResetEvent function (Windows)

Switch View :
ScriptFree
ResetEvent function

Applies to: desktop apps | Metro style apps

Sets the specified event object to the nonsignaled state.

Syntax

BOOL WINAPI ResetEvent(
  __in  HANDLE hEvent
);

Parameters

hEvent [in]

A handle to the event object. The CreateEvent or OpenEvent function returns this handle.

The handle must have the EVENT_MODIFY_STATE access right. For more information, see Synchronization Object Security and Access Rights.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The state of an event object remains nonsignaled until it is explicitly set to signaled by the SetEvent or PulseEvent function. This nonsignaled state blocks the execution of any threads that have specified the event object in a call to one of the wait functions.

The ResetEvent function is used primarily for manual-reset event objects, which must be set explicitly to the nonsignaled state. Auto-reset event objects automatically change from signaled to nonsignaled after a single waiting thread is released.

Resetting an event that is already reset has no effect.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

CreateEvent
Event Objects
OpenEvent
PulseEvent
SetEvent
Synchronization Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Community Content

Carol Buchmiller - MSFT
Is this as unreliable as PulseEvent?
In remarks of PulseEvent, we can find the following:
A thread waiting on a synchronization object can be momentarily removed from the wait state by a kernel-mode APC, and then returned to the wait state after the APC is complete. If the call to PulseEvent occurs during the time when the thread has been removed from the wait state, the thread will not be released because PulseEvent releases only those threads that are waiting at the moment it is called. Therefore, PulseEvent is unreliable and should not be used by new applications. Instead, use condition variables.
I'm writing a software that must work on XP and Server 2003 (they don't support condition variables). I'm trying to simulate a PulseEvent with something like this:
1. Threads A, B, C are all waiting on some event.
2. Thread D sets the event, so it's signaled.
3. Thread A receives priority and resumes.
4. Thread A immediately resets the event, so it becomes unsignaled.
Is it guaranteed that step 2 above will resume threads B and C as well? Or ResetEvent is as unreliable as PulseEvent?

[Carol Buchmiller - MSFT: Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content. ]

dmex
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern bool ResetEvent(SafeWaitHandle handle);

dmex
vb.net syntax
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function ResetEvent(ByVal handle As SafeWaitHandle) As Boolean
End Function