{"id":3387,"date":"2015-07-21T05:29:18","date_gmt":"2015-07-21T10:29:18","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=3387"},"modified":"2015-07-21T05:29:18","modified_gmt":"2015-07-21T10:29:18","slug":"pevents-a-cross-platform-win32-events-library","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/pevents-a-cross-platform-win32-events-library\/","title":{"rendered":"pevents: a cross-platform Win32 events library"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/neosmart\/pevents\" rel=\"nofollow\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright  wp-image-3393 colorbox-3387\" src=\"\/blog\/wp-content\/uploads\/Threads-GitHub.jpg\" alt=\"Threads-GitHub\" width=\"167\" height=\"167\" srcset=\"https:\/\/neosmart.net\/blog\/wp-content\/uploads\/Threads-GitHub.jpg 200w, https:\/\/neosmart.net\/blog\/wp-content\/uploads\/Threads-GitHub-150x150.jpg 150w\" sizes=\"auto, (max-width: 167px) 100vw, 167px\" \/><\/a>pevents, 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.\u00a0<a href=\"https:\/\/neosmart.net\/blog\/2011\/waitformultipleobjects-and-win32-events-for-linux-and-read-write-locks-for-windows\/\" rel=\"follow\">We first released pevents<\/a> 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.<\/p>\n<p>The *nix world has seen a lot of progress when it comes to non-blocking waits in recent years, but it&#8217;s very recently that purely event-driven libraries like epoll and kqueue have properly taken off. In the Windows world, it&#8217;s long-been possible to wait on filesystem and network events with <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms687028(v=vs.85).aspx\" rel=\"follow\"><code>WaitForMultipleObjects<\/code><\/a>\u00a0&#8211; a paradigm most Windows C\/C++ developers are intimately familiar with. One thing that <code>WaitForMultipleObjects<\/code> (and pevents!) can also do rather neatly is wait on multiple mutexes,\u00a0events, and\/or semaphores simultaneously, unblocking when one or more (or all) are triggered or available.<\/p>\n<p><!--more--><\/p>\n<p>Something similar can be accomplished on Linux\/Mac\u00a0using posix condition variables and mutexes \u2013 but for developers more-accustomed to Windows auto or manual reset events and <code>WaitForSingleObjectEx<\/code> or <code>WaitForMultipleObjectsEx<\/code>, 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 &#8211; meaning developers often face\u00a0a 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.<\/p>\n<p>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 <code>CreateEvent<\/code>, <code>SetEvent<\/code>, <code>ResetEvent<\/code>, <code>PulseEvent<\/code>, <code>WaitForSingleObject<\/code>, and <code>WaitForMultipleObjects<\/code> functions. Developers are no longer required to surround all multithreading code with #ifdef to support both Windows and *nix multithreading from a single codebase.<\/p>\n<p><a href=\"https:\/\/github.com\/neosmart\/pevents\/\" rel=\"nofollow\">pevents<\/a> is 100% open source, available\u00a0under the terms of the liberal MIT license. It&#8217;s straight-forward and easy to use for anyone that&#8217;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&#8217;s available to pull and fork on GitHub &#8211; join in!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pevents, 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.\u00a0We first released pevents way back in 2011, when we &hellip; <a href=\"https:\/\/neosmart.net\/blog\/pevents-a-cross-platform-win32-events-library\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[325,759,899,898,11],"class_list":["post-3387","post","type-post","status-publish","format-standard","hentry","category-software","tag-c","tag-github","tag-mulithreading","tag-pevents","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-SD","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=3387"}],"version-history":[{"count":7,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3387\/revisions"}],"predecessor-version":[{"id":3396,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3387\/revisions\/3396"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=3387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=3387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=3387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}