pevents: a cross-platform Win32 events library

Threads-GitHubpevents, our implementation of Windows manual- and auto-reset events for Mac and Linux, is now officially pevents, our truly cross-platform win32 lightweight events library for Windows, Mac, Linux, and other platforms. We first released pevents way back in 2011, when we searched for and were unable to find an existing implementation of Windows events, the basic primitives for thread synchronization on Win32.

The *nix world has seen a lot of progress when it comes to non-blocking waits in recent years, but it’s very recently that purely event-driven libraries like epoll and kqueue have properly taken off. In the Windows world, it’s long-been possible to wait on filesystem and network events with WaitForMultipleObjects – a paradigm most Windows C/C++ developers are intimately familiar with. One thing that WaitForMultipleObjects (and pevents!) can also do rather neatly is wait on multiple mutexes, events, and/or semaphores simultaneously, unblocking when one or more (or all) are triggered or available.

Something similar can be accomplished on Linux/Mac using posix condition variables and mutexes – but for developers more-accustomed to Windows auto or manual reset events and WaitForSingleObjectEx or WaitForMultipleObjectsEx, it can be difficult to make the jump. More importantly, code must be written from the ground-up to either use the WFMO or the condition variable pattern – meaning developers often face a very hard time porting multi-threaded code from Windows to Linux and other posix platforms like Android and iOS (or vice-versa) without a complete rewrite of all thread synchronization.

Enter pevents: a small, light library that implements Windows autoreset and manual-reset events on top of pthreads, and exposes the same API on Windows, Linux, and Mac. With this update, pevents officially supports Windows too, serving as a proxy for the native CreateEvent, SetEvent, ResetEvent, PulseEvent, WaitForSingleObject, and WaitForMultipleObjects functions. Developers are no longer required to surround all multithreading code with #ifdef to support both Windows and *nix multithreading from a single codebase.

pevents is 100% open source, available under the terms of the liberal MIT license. It’s straight-forward and easy to use for anyone that’s previously used Windows events, and has been used by a number of larger teams and projects in the years since its release to great success. It’s available to pull and fork on GitHub – join in!

  • Similar Posts

    Craving more? Here are some posts a vector similarity search turns up as being relevant or similar from our catalog you might also enjoy.
    1. WaitForMultipleObjects and WIN32 events for Linux/OS X/*nix and Read-Write Locks for Windows
    2. rsevents: manual and auto reset events for rust
  • Leave a Reply

    Your email address will not be published. Required fields are marked *