ManualResetEvent class
A manual-reset event for tasks.
On this page
- Use
import ThinkMeta.ConcurrentTasks.Synchronization.ManualResetEvent;- Namespace
ThinkMeta::ConcurrentTasks::Synchronization- Inherits
Waitable,ISuspendCallback- Platforms
- Windows, Linux
Syntax
using ManualResetEvent = _ManualResetEvent<SuspensionKind::Multiple>;
using ManualResetEvent_s = _ManualResetEvent<SuspensionKind::Single>;Template parameters
_SuspensionKindSuspensionKindSuspensionKind::Multiple: any number of waiting tasks;SuspensionKind::Single: at most one waiting task at a time, cheaper, with timeouts.
Remarks
While set, every Wait passes; Set resumes all waiting tasks. Comes as ManualResetEvent (any number of waiters) and ManualResetEvent_s (one waiter). Wait suspends the calling task and needs a task or an OS thread converted with ConvertThreadToTask. Set, Reset and TryWait never suspend and may be called from any thread (the core's I/O thread calls Set). No member reports errors. ManualResetEvent: any number of waiters, no timeouts. A waiter passes once it finds the event set after a resume; a Set taken back by a Reset before the waiter looked is not a pass, the waiter waits on. Destroy the event only when no task can wait on it or set it any more and the last Set has returned; the return of a Wait alone does not mean that: the Set that let the waiter pass may still be taking the list of waiters, and the waiter's own suspend callback may still be re-checking the event. A waiter that wants to destroy the event right after its wait uses ManualResetEvent_s, whose Set is one operation.
See also
AutoResetEvent, SuspensionKind
Names
| Name | Description |
|---|---|
ManualResetEvent |
Manual-reset event for any number of waiting tasks (no timeouts). |
ManualResetEvent_s |
Manual-reset event for at most one waiting task.
Cheaper than |
Constructors
ManualResetEvent
Creates the event.
Syntax
explicit ManualResetEvent(bool isSet = false) noexcept;Parameters
isSetbooltrueto create it set.Default:false
~ManualResetEvent
Destroys the event.
Syntax
~ManualResetEvent() noexcept;Remarks
No task may be waiting on it (asserted in Debug).
Methods
Set
Reset
TryWait
Tells whether the event is set, without changing it.
Syntax
[[nodiscard]] bool TryWait() noexcept;Return value
Type: bool
true if the event is set; otherwise false.
Remarks
Never suspends; any thread.
See also
Wait
Waits until the event is set.
Syntax
void Wait() noexcept;Remarks
Returns at once if the event is set, otherwise suspends the calling task until Set. Task or converted thread only; at most one waiter at a time. A CancelTask does not end it; Wait with Duration::Infinite waits until either.
See also
Waits until the event is set, with a time limit.
Syntax
[[nodiscard]] WaitStatus Wait(Duration timeout) noexcept;Parameters
timeoutDuration- The longest time to wait. Needs
EnableTimers; without it, or withDuration::Infinite, the wait has no limit.
Return value
Type: WaitStatus
WaitStatus::Signaled if the event is set; WaitStatus::TimedOut if it timed out; WaitStatus::Cancelled if the task was cancelled (CancelTask). Unless signaled, the task no longer waits on the event; the event may be set later.
Remarks
Task or converted thread only.
See also
Fields
WaitRechecks
A resumed waiter looks at the event again (see Waitable).
Syntax
static constexpr bool WaitRechecks = true;Remarks
A resume alone does not let a waiter pass: the re-check after a suspension resumes every waiter on the list, among them tasks that started waiting after a Reset.
Generated from ThinkMeta.ConcurrentTasks.API @ c7663c4 (2026-11-19).