{"id":155,"date":"2008-09-30T09:07:50","date_gmt":"2008-09-30T07:07:50","guid":{"rendered":"http:\/\/pocoproject.org\/poco\/blog\/?p=154"},"modified":"2008-09-30T09:07:50","modified_gmt":"2008-09-30T07:07:50","slug":"nullmutex","status":"publish","type":"post","link":"https:\/\/pocoproject.org\/blog\/?p=155","title":{"rendered":"NullMutex"},"content":{"rendered":"<p>As of revision 896 the POCO sourceforge trunk features a new class: the NullMutex (Poco\/Mutex.h)<\/p>\n<p>You now probably ask yourself: What&#8217;s so special about this class? Because &#8211; as the name suggests &#8211; it does nothing.<br \/>\nAnd that&#8217;s exactly why we needed it. Mostly all components of POCO are thread-safe. While this is generally a good thing, it also hurts performance when this thread-safeness is not needed.<\/p>\n<p>The first classes to profit from this feature are all the classes from the caching and the events framework.<\/p>\n<p>Events now have a second optional template parameter (which defaults to FastMutex) which allow you to specify the mutex. To disable thread-safeness for an event write:<\/p>\n<p><code>Poco::BasicEvent&lt;int, NullMutex&gt;<\/code><\/p>\n<p>The caching framework can benefit even more from this extension. Inserting an value into the cache requires a lock for the insert and then another lock when we fire the add event! In a full multithreaded environment all these locks are needed but what if you don&#8217;t care about the events at all and never register to them? Write<\/p>\n<p><code> Poco::LRUCache&lt;MyKey, MyValue, FastMutex, NullMutex&gt; <\/code><\/p>\n<p>to disable thread-safeness for the caches events only.<\/p>\n<p>To additionally disable thread-safeness for the cache, write<\/p>\n<p><code> Poco::LRUCache&lt;MyKey, MyValue, NullMutex, NullMutex&gt; <\/code><\/p>\n<p>And if you don&#8217;t care about the mutex stuff at all? Then write<\/p>\n<p><code> Poco::LRUCache&lt;MyKey, MyValue&gt; <\/code><br \/>\n<code>Poco::BasicEvent&lt;int&gt;<\/code><\/p>\n<p>as you used to do prior. The event\/cache extensions are backwards compatible. When you don&#8217;t specify a mutex, a FastMutex is used per default.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As of revision 896 the POCO sourceforge trunk features a new class: the NullMutex (Poco\/Mutex.h) You now probably ask yourself: What&#8217;s so special about this class? Because &#8211; as the name suggests &#8211; it does nothing. And that&#8217;s exactly why we needed it. Mostly all components of POCO are thread-safe. While this is generally a [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155"}],"version-history":[{"count":0,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions"}],"wp:attachment":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}