Le 20/12/12 17:24, Fredrik Orderud a écrit :
This is a good starting point. Do you expect that shared_pri_mutex< UNSPECIFIED_PRIORITY> behaves as shared_mutex?Attached is an early "draft" implementation of "shared_pri_mutex" with support for the following prioritization policies: UNSPECIFIED_PRIORITY, EXCLUSIVE_PRIORITY and SHARED_PRIORITY. Associated test code is attached in main.cpp. The implementation is based on a stripped-down version of boost/thread/pthread/shared_mutex.hpp, and implements policies through an enum template argument.
The enum seems ok to me, but maybe, having specific classes at the user level could introduce less constraints: shared_mutex, shared_mutex_prio_shared, , shared_mutex_prio_exclusive. This doesn't means that the implementation could not use a unique implementation as far as there is no loss on performances.The policies could probably also be implemented with a class hierarchy if preferred.
I would prefer to integrate into Boost an implementation that takes in account upgrade-locking and timed operations. As soon as we have a complete and correct implementation, with enough test and documentation we could integrate them in a release. The documentation will need a motivation, why do we need them? If you can work on some of these subjects the integration could be do sooner.Could you (or someone else) please provide some feedback on the "shared_pri_mutex" concept, and realism of getting a revised/extended implementation incorporated into boost::thread at some point?
Anyway, for the time been I have some minor remarks:
* the enum literals should be in lowercase and I would prefer a enum class.
//enum class shared_mutex_priority
BOOST_SCOPED_ENUM_DECLARE_BEGIN(shared_mutex_priority)
{
unspecified,
exclusive,
shared
}
* mutex are not copiable
BOOST_THREAD_NO_COPYABLE(shared_pri_mutex)
* protect the use of interruptions with BOOST_THREAD_PROVIDES_INTERRUPTIONS as in trunk
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
boost::this_thread::disable_interruption do_not_disturb;
#endif
* boost::mutex::scoped_lock is deprecated
Use
boost::unique_lock<boost::mutex> lk(state_change);
instead of
boost::mutex::scoped_lock lk(state_change);
as in trunk.
Maybe it is worth creating a Trac ticket.