The POCO C++ Libraries Blog


Filed under: Uncategorized by peter at 09:07

As of revision 896 the POCO sourceforge trunk features a new class: the NullMutex (Poco/Mutex.h)

You now probably ask yourself: What’s so special about this class? Because – as the name suggests – it does nothing.
And that’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.

The first classes to profit from this feature are all the classes from the caching and the events framework.

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:

Poco::BasicEvent<int, NullMutex>

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’t care about the events at all and never register to them? Write

Poco::LRUCache<MyKey, MyValue, FastMutex, NullMutex>

to disable thread-safeness for the caches events only.

To additionally disable thread-safeness for the cache, write

Poco::LRUCache<MyKey, MyValue, NullMutex, NullMutex>

And if you don’t care about the mutex stuff at all? Then write

Poco::LRUCache<MyKey, MyValue>

as you used to do prior. The event/cache extensions are backwards compatible. When you don’t specify a mutex, a FastMutex is used per default.

No Comments »

No comments yet.

RSS RSS feed for comments on this post. TrackBack URI

Leave a comment