#synchronization #events #signals #win32


Manual and auto reset events for signaling remote threads and building synchronization primitives

4 releases

0.2.1 Dec 24, 2019
0.2.0 Sep 13, 2018
0.1.1 Sep 13, 2018
0.1.0 Sep 12, 2018

#250 in Concurrency

Download history 10/week @ 2021-06-27 9/week @ 2021-07-04 15/week @ 2021-07-11 11/week @ 2021-07-18 24/week @ 2021-07-25 16/week @ 2021-08-01 11/week @ 2021-08-08 13/week @ 2021-08-15 10/week @ 2021-08-22 3/week @ 2021-08-29 4/week @ 2021-09-05 11/week @ 2021-09-12 4/week @ 2021-09-19 20/week @ 2021-09-26 4/week @ 2021-10-03 10/week @ 2021-10-10

77 downloads per month
Used in 2 crates

MIT license

241 lines


crates.io docs.rs

This crate contains a cross-platform implementation of auto and manual reset events similar to those found in Microsoft Windows, implemented on top of the core parking lot crate.

About Events

An event is best compared to a waitable boolean, and can have either of two states: set and unset. Callers may directly wait on the event itself, foregoing the need for an associated condition variable and mutex.

Events come in two flavors, AutoResetEvent and ManualResetEvent, which differ in their behavior when it comes to setting (aka signalling) an event. An AutoResetEvent, once signalled, permits exactly one (and only one) past or future caller to unblock while waiting for the same event, whereas a ManualResetEvent lacks such fine-grained control and is either signalled and unblocked for all past/future waiters or none (until its state is toggled).


// create a new, initially unset event
let event = AutoResetEvent::new(State::Unset);

// and wrap it in an ARC to allow sharing across thread boundaries
let event = Arc::new(event);

// create a worker thread to complete some task
	let shared = event.clone();
	std::thread::spawn(|| {
		// perform some task
		// and signal to ONE waiting thread that the result is ready


// wait for the spawned thread to finish the queued work


Structs ManualResetEvent and AutoResetEvent, both implementing the trait Event which exposes an API that permits waiting indefinitely, waiting for zero time, and waiting for a fixed time limit (Duration) for an event to be triggered.

See the documentation for more info.

When to use

Generally speaking, a mutex or condition variable should always be preferred when it comes to protecting a critical section and ensuring exclusive access due to their well-understood synchronization paradigms and wide support. However, there are other times when a synchronization primitve not coupled to an explicit critical section or protected data is required, in which case it similarly does not make sense to use a mutex and a critical section when a single alternative synchronization primitive is what is actually required.

Any time you find yourself needing a Mutex<bool> and an associated condition variable to set/test/clear a boolean flag to synchronize state across threads, you should reach for either a manual- or auto-reset event instead.


rsevents is written and maintained by Mahmoud Al-Qudsi <mqudsi@neosmart.net> of NeoSmart Technologies <https://neosmart.net/> and released to the general public under the terms of the MIT public license.