Almost every line of code in Boost.Thread has been changed since the 1.34 release of boost. However, most of the interface changes have been extensions, so the new code is largely backwards-compatible with the old code. The new features and breaking changes are described below.
New Features
-
Instances of
boost::threadand of the various lock types are now movable. - Threads can be interrupted at interruption points.
-
Condition variables can now be used with any type that implements the
Lockableconcept, through the use ofboost::condition_variable_any(boost::conditionis atypedeftoboost::condition_variable_any, provided for backwards compatibility).boost::condition_variableis provided as an optimization, and will only work withboost::unique_lock<boost::mutex>(boost::mutex::scoped_lock). -
Thread IDs are separated from
boost::thread, so a thread can obtain it's own ID (usingboost::this_thread::get_id()), and IDs can be used as keys in associative containers, as they have the full set of comparison operators. -
Timeouts are now implemented using the Boost DateTime library, through a
typedef
boost::system_timefor absolute timeouts, and with support for relative timeouts in many cases.boost::xtimeis supported for backwards compatibility only. -
Locks are implemented as publicly accessible templates
boost::lock_guard,boost::unique_lock,boost::shared_lock, andboost::upgrade_lock, which are templated on the type of the mutex. TheLockableconcept has been extended to include publicly availablelock()andunlock()member functions, which are used by the lock types.
Breaking Changes
The list below should cover all changes to the public interface which break backwards compatibility.
-
boost::try_mutexhas been removed, and the functionality subsumed intoboost::mutex.boost::try_mutexis left as atypedef, but is no longer a separate class. -
boost::recursive_try_mutexhas been removed, and the functionality subsumed intoboost::recursive_mutex.boost::recursive_try_mutexis left as atypedef, but is no longer a separate class. -
boost::detail::thread::lock_opshas been removed. Code that relies on thelock_opsimplementation detail will no longer work, as this has been removed, as it is no longer necessary now that mutex types now have publiclock()andunlock()member functions. -
scoped_lockconstructors with a second parameter of typeboolare no longer provided. With previous boost releases,boost::mutex::scoped_lock some_lock(some_mutex,false);
could be used to create a lock object that was associated with a mutex, but did not lock it on construction. This facility has now been replaced with the constructor that takes aboost::defer_lock_typeas the second parameter:boost::mutex::scoped_lock some_lock(some_mutex,boost::defer_lock);
-
The broken
boost::read_write_mutexhas been replaced withboost::shared_mutex.
