diff --git a/doc/changes.qbk b/doc/changes.qbk index f83a1f14..60bcd6ac 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -12,50 +12,54 @@ Breaking changes: +[warning BOOST_THREAD_VERSION==3 by default since Boost 1.53. So that all the deprecated features since 1.50 are not included by default. You can change this by setting the appropriated define (see Configuration section). +] -Deprecated Features: +Deprecated features: -Deprecated features since boost 1.53 available only until boost 1.58: +[warning Deprecated features since boost 1.53 will be available only until boost 1.58.] -* packaged_task is deprecated, use instead packaged_task. See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK +* C++11 compliance: packaged_task is deprecated, use instead packaged_task. +See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK * [@http://svn.boost.org/trac/boost/ticket/7537 #7537] deprecate Mutex::scoped_lock and scoped_try_lock and boost::condition New Features: - - * [@http://svn.boost.org/trac/boost/ticket/6270 #6270] c++11 compliance: Add thread constructor from movable callable and movable arguments Provided when BOOST_THREAD_PROVIDES_VARIADIC_THREAD is defined (Default value from Boost 1.55): See BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD. +* [@http://svn.boost.org/trac/boost/ticket/7280 #7280] C++11 compliance: Add promise::...at_thread_exit functions + * [@http://svn.boost.org/trac/boost/ticket/7281 #7281] C++11 compliance: Add ArgTypes to packaged_task template. Provided when BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK is defined (Default value from Boost 1.55). See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK. -* [@http://svn.boost.org/trac/boost/ticket/7412 #7412] c++11 compliance: Add async from movable callable and movable arguments +* [@http://svn.boost.org/trac/boost/ticket/7282 #7282] C++11 compliance: Add packaged_task::make_ready_at_thread_exit function + +* [@http://svn.boost.org/trac/boost/ticket/7412 #7412] C++11 compliance: Add async from movable callable and movable arguments Provided when BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK are defined (Default value from Boost 1.55): See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK, BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD. -[/* [@http://svn.boost.org/trac/boost/ticket/7413 #7413] c++11 compliance: Add async when the launch policy is deferred.] -* [@http://svn.boost.org/trac/boost/ticket/7414 #7414] c++11 compliance: future::get post-condition should be valid()==false. +* [@http://svn.boost.org/trac/boost/ticket/7413 #7413] C++11 compliance: Add async when the launch policy is deferred. +* [@http://svn.boost.org/trac/boost/ticket/7414 #7414] C++11 compliance: future::get post-condition should be valid()==false. * [@http://svn.boost.org/trac/boost/ticket/7414 #7444] Async: Add make_future/make_shared_future. * [@http://svn.boost.org/trac/boost/ticket/7445 #7445] Async: Add future<>.then. * [@http://svn.boost.org/trac/boost/ticket/7449 #7449] Synchro: Add a synchronized value class. -* [@http://svn.boost.org/trac/boost/ticket/7540 #7540] Add a helper class that join a thread on destruction. -* [@http://svn.boost.org/trac/boost/ticket/7541 #7541] Add a thread wrapper class that joins on destruction. -* [@http://svn.boost.org/trac/boost/ticket/7587 #7587] Add strict_lock and nested_strict_lock -* [@http://svn.boost.org/trac/boost/ticket/7588 #7588] Split the locks.hpp in several files to limit depedencies -* [@http://svn.boost.org/trac/boost/ticket/7589 #7589] Add polymorphic lockables -* [@http://svn.boost.org/trac/boost/ticket/7590 #7590] Add lockable concept checkers based on Boost.ConceptCheck -* [@http://svn.boost.org/trac/boost/ticket/7592 #7592] Add a null_mutex that is a no-op and that is a model of UpgardeLockable -* [@http://svn.boost.org/trac/boost/ticket/7593 #7593] Add a externally_locked class -* [@http://svn.boost.org/trac/boost/ticket/7590 #7594] Allow to disable thread interruptions +* [@http://svn.boost.org/trac/boost/ticket/7540 #7540] Threads: Add a helper class that join a thread on destruction. +* [@http://svn.boost.org/trac/boost/ticket/7541 #7541] Threads: Add a thread wrapper class that joins on destruction. +* [@http://svn.boost.org/trac/boost/ticket/7587 #7587] Synchro: Add strict_lock and nested_strict_lock +* [@http://svn.boost.org/trac/boost/ticket/7588 #7588] Synchro: Split the locks.hpp in several files to limit dependencies +* [@http://svn.boost.org/trac/boost/ticket/7589 #7589] Synchro: Add polymorphic lockables +* [@http://svn.boost.org/trac/boost/ticket/7590 #7590] Synchro: Add lockable concept checkers based on Boost.ConceptCheck +* [@http://svn.boost.org/trac/boost/ticket/7592 #7592] Synchro: Add a null_mutex that is a no-op and that is a model of UpgardeLockable +* [@http://svn.boost.org/trac/boost/ticket/7593 #7593] Synchro: Add a externally_locked class +* [@http://svn.boost.org/trac/boost/ticket/7590 #7594] Threads: Allow to disable thread interruptions Fixed Bugs: - [heading Version 3.1.0 - boost 1.52] Deprecated Features: diff --git a/doc/configuration.qbk b/doc/configuration.qbk index dbb752d2..f1ac3a46 100644 --- a/doc/configuration.qbk +++ b/doc/configuration.qbk @@ -9,6 +9,17 @@ [section:configuration Configuration] +[table Default Values for Configurable Features + [[Feature] [Anti-Feature] [V2] [V3] [V4] ] + [[USES_CHRONO] [DONT_USE_CHRONO] [YES] [YES] [YES] ] + [[USES_MOVE] [DONT_USE_MOVE] [YES] [YES] [YES] ] + [[USES_DATETIME] [DONT_USE_DATETIME] [YES] [NO] [NO] ] + [[PROVIDES_THREAD_EQ] [DONT_PROVIDE_THREAD_EQ] [YES] [YES] [NO] ] + [[PROVIDES_CONDITION] [DONT_PROVIDE_CONDITION] [YES] [YES] [NO] ] + [[PROVIDES_NESTED_LOCKS] [DONT_PROVIDE_NESTED_LOCKS] [YES] [YES] [NO] ] + [[PROVIDES_BASIC_THREAD_ID] [PROVIDES_BASIC_THREAD_ID] [NO] [YES] [YES] ] +] + [section:chrono Boost.Chrono] Boost.Thread uses by default Boost.Chrono for the time related functions and define `BOOST_THREAD_USES_CHRONO` if `BOOST_THREAD_DONT_USE_CHRONO` is not defined. The user should define `BOOST_THREAD_DONT_USE_CHRONO` for compilers that don't work well with Boost.Chrono. diff --git a/doc/future_ref.qbk b/doc/future_ref.qbk index 2cd60855..e9f1aba0 100644 --- a/doc/future_ref.qbk +++ b/doc/future_ref.qbk @@ -407,9 +407,14 @@ value. Otherwise, returns an rvalue-reference to the value stored in the asynchr [[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link `this->get_state()`] returns __ready__.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception stored in the -asynchronous result in place of a value.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception stored in the asynchronous result in place of a value. +]] [[Notes:] [`get()` is an ['interruption point].]] @@ -426,9 +431,14 @@ asynchronous result in place of a value.]] [[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result +associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -461,9 +471,13 @@ invoked prior to waiting.]] [[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has elapsed, `false` otherwise.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and [unique_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -495,9 +509,13 @@ prior to waiting.]] [[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has passed, `false` otherwise.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and [unique_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -529,9 +547,13 @@ invoked prior to waiting.]] ]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and [unique_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -563,9 +585,13 @@ prior to waiting.]] ]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and [unique_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -786,8 +812,12 @@ __shared_future_wait__, and returns a `const` reference to the result.]] [[Returns:] [If the result type `R` is a reference, returns the stored reference. If `R` is `void`, there is no return value. Otherwise, returns a `const` reference to the value stored in the asynchronous result.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the -result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. +]] [[Notes:] [`get()` is an ['interruption point].]] @@ -804,8 +834,12 @@ result associated with `*this` is not ready at the point of the call, and the cu [[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the +[[Throws:] [ +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [[shared_future_is_ready_link `this->is_ready()`] returns `true`. [shared_future_get_state_link @@ -831,9 +865,13 @@ invoked prior to waiting.]] [[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has elapsed, `false` otherwise.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ + +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and [shared_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -857,9 +895,12 @@ prior to waiting.]] [[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has passed, `false` otherwise.]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and [shared_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -892,9 +933,12 @@ invoked prior to waiting.]] ]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called.]] [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and [shared_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -926,9 +970,13 @@ prior to waiting.]] ]] -[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result -associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the -['wait callback] if such a callback is called.]] +[[Throws:] [ +- __future_uninitialized__ if `*this` is not associated with an asynchronous result. + +- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted. + +- Any exception thrown by the ['wait callback] if such a callback is called. +]] [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and [shared_future_get_state_link `this->get_state()`] returns __ready__.]] @@ -1042,14 +1090,12 @@ associated with `*this` is ready for retrieval, __waiting__ otherwise.]] __unique_future__ get_future(); // Set the value - void set_value(R& r); - void set_value(R&& r); + void set_value(see below); void set_exception(boost::exception_ptr e); // setting the result with deferred notification - // void set_value_at_thread_exit(const R& r); // NOT YET IMPLEMENTED - // void set_value_at_thread_exit(see below); // NOT YET IMPLEMENTED - // void set_exception_at_thread_exit(exception_ptr p); // NOT YET IMPLEMENTED + void set_value_at_thread_exit(see below); + void set_exception_at_thread_exit(exception_ptr p); template void set_wait_callback(F f); // EXTENSION @@ -1163,15 +1209,24 @@ memory necessary could not be allocated.]] [variablelist -[[Effects:] [If `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with -`*this`. Store the value `r` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous -result are woken.]] +[[Effects:] [ +- If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with `*this`. + +- Store the value `r` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous +result are woken. +]] [[Postconditions:] [All futures waiting on the asynchronous result are ['ready] and __unique_future_has_value__ or __shared_future_has_value__ for those futures shall return `true`.]] -[[Throws:] [__promise_already_satisfied__ if the result associated with `*this` is already ['ready]. `std::bad_alloc` if the memory -required for storage of the result cannot be allocated. Any exception thrown by the copy or move-constructor of `R`.]] +[[Throws:] [ +- __promise_already_satisfied__ if the result associated with `*this` is already ['ready]. + +- __broken_promise__ if `*this` has no shared state. + +- `std::bad_alloc` if the memory required for storage of the result cannot be allocated. + +- Any exception thrown by the copy or move-constructor of `R`.]] ] @@ -1183,21 +1238,83 @@ required for storage of the result cannot be allocated. Any exception thrown by [variablelist -[[Effects:] [If `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with -`*this`. Store the exception `e` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous +[[Effects:] [ +- If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with +`*this`. + +- Store the exception `e` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous result are woken.]] [[Postconditions:] [All futures waiting on the asynchronous result are ['ready] and __unique_future_has_exception__ or __shared_future_has_exception__ for those futures shall return `true`.]] -[[Throws:] [__promise_already_satisfied__ if the result associated with `*this` is already ['ready]. `std::bad_alloc` if the memory -required for storage of the result cannot be allocated.]] +[[Throws:] [ +- __promise_already_satisfied__ if the result associated with `*this` is already ['ready]. + +- __broken_promise__ if `*this` has no shared state. + +- `std::bad_alloc` if the memory required for storage of the result cannot be allocated. +]] ] [endsect] -[section:set_wait_callback Member Function `set_wait_callback()`] +[section:set_value_at_thread_exit Member Function `set_value_at_thread_exit()`] + + void set_value_at_thread_exit(R&& r); + void set_value_at_thread_exit(const R& r); + void promise::set_value_at_thread_exit(R& r); + void promise::set_value_at_thread_exit(); + +[variablelist + +[[Effects:] [ +Stores the value r in the shared state without making that state ready immediately. +Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration +associated with the current thread have been destroyed.]] + + +[[Throws:] [ +- __promise_already_satisfied__ if the result associated with `*this` is already ['ready]. + +- __broken_promise__ if `*this` has no shared state. + +- `std::bad_alloc` if the memory required for storage of the result cannot be allocated. + +- Any exception thrown by the copy or move-constructor of `R`. +]] + +] + +[endsect] + +[section:set_exception_at_thread_exit Member Function `set_exception_at_thread_exit()`] + + void set_exception_at_thread_exit(boost::exception_ptr e); + +[variablelist + +[[Effects:] [ +Stores the exception pointer p in the shared state without making that state ready immediately. +Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration + associated with the current thread have been destroyed.]] + +[[Postconditions:] [All futures waiting on the asynchronous result are ['ready] and __unique_future_has_exception__ or +__shared_future_has_exception__ for those futures shall return `true`.]] + +[[Throws:] [ +- __promise_already_satisfied__ if the result associated with `*this` is already ['ready]. + +- __broken_promise__ if `*this` has no shared state. + +- `std::bad_alloc` if the memory required for storage of the result cannot be allocated. +]] + +] + +[endsect] +[section:set_wait_callback Member Function `set_wait_callback()` EXTENSION] template void set_wait_callback(F f); @@ -1260,7 +1377,7 @@ or __shared_future__ associated with this result, and the result is not ['ready] // execution void operator()(ArgTypes... ); - // void make_ready_at_thread_exit(ArgTypes...); // NOT YET IMPLEMENTED + void make_ready_at_thread_exit(ArgTypes...); void reset(); template @@ -1281,8 +1398,12 @@ as invoking `f`.]] [[Effects:] [Constructs a new __packaged_task__ with `boost::forward(f)` stored as the associated task.]] -[[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data -structures could not be allocated.]] +[[Throws:] [ + +- Any exceptions thrown by the copy (or move) constructor of `f`. + +- `std::bad_alloc` if memory for the internal data structures could not be allocated. +]] [[Notes:] [The R(*f)(ArgTypes...)) overload to allow passing a function without needing to use `&`.]] @@ -1395,13 +1516,40 @@ asynchronous result associated with this task are woken.]] [[Postconditions:] [All futures waiting on the asynchronous result are ['ready]]] -[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of -__packaged_task__. __task_already_started__ if the task has already been invoked.]] +[[Throws:] [ + +- __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__. + +- __task_already_started__ if the task has already been invoked.]] ] [endsect] +[section:make_ready_at_thread_exit Member Function `make_ready_at_thread_exit()`] + + void make_ready_at_thread_exit(ArgTypes...); + +[variablelist + +[[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally, +the return value is stored as the asynchronous result, otherwise the exception thrown is stored. +In either case, this is done without making that state ready immediately. +Schedules the shared state to be made ready when the current thread exits, after all objects of thread storage +duration associated with the current thread have been destroyed.]] + +[[Throws:] [ + +- __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__. + +- __task_already_started__ if the task has already been invoked. +]] + +] + +[endsect] + + [section:reset Member Function `reset()`] void reset(); diff --git a/example/condition.cpp b/example/condition.cpp index 52475d6c..1d6d8058 100644 --- a/example/condition.cpp +++ b/example/condition.cpp @@ -7,13 +7,13 @@ #include #include #include -#include +#include #include class bounded_buffer : private boost::noncopyable { public: - typedef boost::mutex::scoped_lock lock; + typedef boost::unique_lock lock; bounded_buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { } @@ -40,7 +40,7 @@ public: private: int begin, end, buffered; std::vector circular_buf; - boost::condition buffer_not_full, buffer_not_empty; + boost::condition_variable_any buffer_not_full, buffer_not_empty; boost::mutex monitor; }; @@ -54,7 +54,7 @@ void sender() { buf.send(n); if(!(n%10000)) { - boost::mutex::scoped_lock io_lock(io_mutex); + boost::unique_lock io_lock(io_mutex); std::cout << "sent: " << n << std::endl; } ++n; @@ -68,7 +68,7 @@ void receiver() { n = buf.receive(); if(!(n%10000)) { - boost::mutex::scoped_lock io_lock(io_mutex); + boost::unique_lock io_lock(io_mutex); std::cout << "received: " << n << std::endl; } } while (n != -1); // -1 indicates end of buffer diff --git a/example/make_future.cpp b/example/make_future.cpp index ef246fcd..e9fd587e 100644 --- a/example/make_future.cpp +++ b/example/make_future.cpp @@ -15,7 +15,7 @@ boost::future compute(int x) if (x == 0) return boost::make_future(0); if (x < 0) return boost::make_future(-1); //boost::future f1 = boost::async([]() { return x+1; }); - boost::future f1 = boost::async(p1); + boost::future f1 = boost::async(boost::launch::async, p1); return boost::move(f1); } boost::shared_future shared_compute(int x) diff --git a/example/monitor.cpp b/example/monitor.cpp index ff02f5b6..d8855d27 100644 --- a/example/monitor.cpp +++ b/example/monitor.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -20,7 +20,7 @@ template class buffer_t { public: - typedef typename M::scoped_lock scoped_lock; + typedef boost::unique_lock scoped_lock; buffer_t(int n) : p(0), c(0), full(0), buf(n) @@ -60,7 +60,7 @@ public: for (int n = 0; n < ITERS; ++n) { { - boost::mutex::scoped_lock lock(io_mutex); + boost::unique_lock lock(io_mutex); std::cout << "sending: " << n << std::endl; } get_buffer().send(n); @@ -73,7 +73,7 @@ public: { int n = get_buffer().receive(); { - boost::mutex::scoped_lock lock(io_mutex); + boost::unique_lock lock(io_mutex); std::cout << "received: " << n << std::endl; } } @@ -81,7 +81,7 @@ public: private: M mutex; - boost::condition cond; + boost::condition_variable_any cond; unsigned int p, c, full; std::vector buf; }; diff --git a/example/mutex.cpp b/example/mutex.cpp index b276d549..9e476208 100644 --- a/example/mutex.cpp +++ b/example/mutex.cpp @@ -1,7 +1,7 @@ // Copyright (C) 2001-2003 // William E. Kempf // -// Distributed under the Boost Software License, Version 1.0. (See accompanying +// Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include @@ -16,7 +16,7 @@ public: counter() : count(0) { } int increment() { - boost::mutex::scoped_lock scoped_lock(mutex); + boost::unique_lock scoped_lock(mutex); return ++count; } @@ -30,7 +30,7 @@ counter c; void change_count() { int i = c.increment(); - boost::mutex::scoped_lock scoped_lock(io_mutex); + boost::unique_lock scoped_lock(io_mutex); std::cout << "count == " << i << std::endl; } diff --git a/example/recursive_mutex.cpp b/example/recursive_mutex.cpp index c5199545..a5894832 100644 --- a/example/recursive_mutex.cpp +++ b/example/recursive_mutex.cpp @@ -1,7 +1,7 @@ // Copyright (C) 2001-2003 // William E. Kempf // -// Distributed under the Boost Software License, Version 1.0. (See accompanying +// Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include @@ -14,12 +14,12 @@ public: counter() : count(0) { } int add(int val) { - boost::recursive_mutex::scoped_lock scoped_lock(mutex); + boost::unique_lock scoped_lock(mutex); count += val; return count; } int increment() { - boost::recursive_mutex::scoped_lock scoped_lock(mutex); + boost::unique_lock scoped_lock(mutex); return add(1); } diff --git a/example/scoped_thread.cpp b/example/scoped_thread.cpp index 9c7e4e76..a6d8814f 100644 --- a/example/scoped_thread.cpp +++ b/example/scoped_thread.cpp @@ -4,9 +4,9 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#define BOOST_THREAD_VERSION 3 #include -//#include #include void do_something(int& i) @@ -36,6 +36,10 @@ void do_something_in_current_thread() { } +//void do_something_with_current_thread(boost::thread&& th) +//{ +// th.join(); +//} int main() { @@ -52,6 +56,14 @@ int main() do_something_in_current_thread(); } +// { +// int some_local_state; +// boost::thread t(( func(some_local_state) )); +// boost::strict_scoped_thread<> g( (boost::move(t)) ); +// +// do_something_in_current_thread(); +// do_something_with_current_thread(boost::thread(g)); +// } return 0; } diff --git a/example/starvephil.cpp b/example/starvephil.cpp index 24e6e010..37752980 100644 --- a/example/starvephil.cpp +++ b/example/starvephil.cpp @@ -25,18 +25,18 @@ public: void get(int id) { - boost::mutex::scoped_lock lock(m_mutex); + boost::unique_lock lock(m_mutex); while (m_chickens == 0) { { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Phil" << id << ": wot, no chickens? I'll WAIT ..." << std::endl; } m_condition.wait(lock); } { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Phil" << id << ": those chickens look good ... one please ..." << std::endl; } @@ -44,9 +44,9 @@ public: } void put(int value) { - boost::mutex::scoped_lock lock(m_mutex); + boost::unique_lock lock(m_mutex); { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Chef: ouch ... make room ... this dish is " << "very hot ..." << std::endl; @@ -57,7 +57,7 @@ public: boost::thread::sleep(xt); m_chickens += value; { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Chef: more chickens ... " << m_chickens << " now available ... NOTIFYING ..." << std::endl; @@ -77,13 +77,13 @@ void chef() { const int chickens = 4; { - boost::mutex::scoped_lock lock(iomx); + boost::unique_lock lock(iomx); std::cout << "(" << clock() << ") Chef: starting ..." << std::endl; } for (;;) { { - boost::mutex::scoped_lock lock(iomx); + boost::unique_lock lock(iomx); std::cout << "(" << clock() << ") Chef: cooking ..." << std::endl; } boost::xtime xt; @@ -91,7 +91,7 @@ void chef() xt.sec += 2; boost::thread::sleep(xt); { - boost::mutex::scoped_lock lock(iomx); + boost::unique_lock lock(iomx); std::cout << "(" << clock() << ") Chef: " << chickens << " chickens, ready-to-go ..." << std::endl; } @@ -104,7 +104,7 @@ struct phil phil(int id) : m_id(id) { } void run() { { - boost::mutex::scoped_lock lock(iomx); + boost::unique_lock lock(iomx); std::cout << "(" << clock() << ") Phil" << m_id << ": starting ..." << std::endl; } @@ -118,13 +118,13 @@ struct phil boost::thread::sleep(xt); } { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Phil" << m_id << ": gotta eat ..." << std::endl; } g_canteen.get(m_id); { - boost::mutex::scoped_lock lk(iomx); + boost::unique_lock lk(iomx); std::cout << "(" << clock() << ") Phil" << m_id << ": mmm ... that's good ..." << std::endl; } diff --git a/example/tennis.cpp b/example/tennis.cpp index 1a45eb1f..93e5a46a 100644 --- a/example/tennis.cpp +++ b/example/tennis.cpp @@ -41,7 +41,7 @@ char* player_name(int state) void player(void* param) { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); int active = (int)param; int other = active == PLAYER_A ? PLAYER_B : PLAYER_A; @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) xt.sec += 1; boost::thread::sleep(xt); { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); std::cout << "---Noise ON..." << std::endl; } @@ -116,7 +116,7 @@ int main(int argc, char* argv[]) cond.notify_all(); { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); std::cout << "---Noise OFF..." << std::endl; state = GAME_OVER; cond.notify_all(); diff --git a/example/thread_group.cpp b/example/thread_group.cpp index fd11a57c..42976bbd 100644 --- a/example/thread_group.cpp +++ b/example/thread_group.cpp @@ -12,7 +12,7 @@ boost::mutex mutex; void increment_count() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); std::cout << "count = " << ++count << std::endl; } diff --git a/include/boost/thread/barrier.hpp b/include/boost/thread/barrier.hpp index 4fd89883..e041ffab 100644 --- a/include/boost/thread/barrier.hpp +++ b/include/boost/thread/barrier.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,7 @@ namespace boost bool wait() { - boost::mutex::scoped_lock lock(m_mutex); + boost::unique_lock lock(m_mutex); unsigned int gen = m_generation; if (--m_count == 0) diff --git a/include/boost/thread/detail/config.hpp b/include/boost/thread/detail/config.hpp index e0d28783..a7eada07 100644 --- a/include/boost/thread/detail/config.hpp +++ b/include/boost/thread/detail/config.hpp @@ -25,6 +25,21 @@ #endif #endif +#if defined BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED +#define BOOST_THREAD_ASSERT_PRECONDITION(EXPR, EX) \ + if (EXPR) {} else boost::throw_exception(EX) +#define BOOST_THREAD_VERIFY_PRECONDITION(EXPR, EX) \ + if (EXPR) {} else boost::throw_exception(EX) +#define BOOST_THREAD_THROW_ELSE_RETURN(EX, RET) \ + boost::throw_exception(EX) +#else +#define BOOST_THREAD_ASSERT_PRECONDITION(EXPR, EX) +#define BOOST_THREAD_VERIFY_PRECONDITION(EXPR, EX) \ + (void)(EXPR) +#define BOOST_THREAD_THROW_ELSE_RETURN(EX, RET) \ + return (RET) +#endif + // This compiler doesn't support Boost.Chrono #if defined __IBMCPP__ && (__IBMCPP__ < 1100) && ! defined BOOST_THREAD_DONT_USE_CHRONO #define BOOST_THREAD_DONT_USE_CHRONO @@ -54,9 +69,9 @@ #endif -// Default version is 2 +// Default version is 3 #if !defined BOOST_THREAD_VERSION -#define BOOST_THREAD_VERSION 2 +#define BOOST_THREAD_VERSION 4 #else #if BOOST_THREAD_VERSION!=2 && BOOST_THREAD_VERSION!=3 && BOOST_THREAD_VERSION!=4 #error "BOOST_THREAD_VERSION must be 2, 3 or 4" diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp index 988fc809..71564343 100644 --- a/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -14,7 +14,9 @@ #endif #include #include +#if defined BOOST_THREAD_USES_DATETIME #include +#endif #include #include #include @@ -257,7 +259,7 @@ namespace boost class F > explicit thread(BOOST_THREAD_RV_REF(F) f - , typename disable_if::type, thread>, dummy* >::type=0 + //, typename disable_if::type, thread>, dummy* >::type=0 ): thread_info(make_thread_info(thread_detail::decay_copy(boost::forward(f)))) { @@ -266,7 +268,7 @@ namespace boost template < class F > - thread(attributes& attrs, BOOST_THREAD_RV_REF(F) f): + thread(attributes const& attrs, BOOST_THREAD_RV_REF(F) f): thread_info(make_thread_info(thread_detail::decay_copy(boost::forward(f)))) { start_thread(attrs); @@ -281,7 +283,7 @@ namespace boost start_thread(); } template - thread(attributes& attrs, F f): + thread(attributes const& attrs, F f): thread_info(make_thread_info(f)) { start_thread(attrs); @@ -290,15 +292,18 @@ namespace boost template explicit thread(F f , typename disable_if_c< - boost::is_convertible::value || is_same::type, thread>::value, - dummy* >::type=0): + boost::is_convertible::value + //|| is_same::type, thread>::value + , dummy* >::type=0 + ): thread_info(make_thread_info(f)) { start_thread(); } template - thread(attributes& attrs, F f - , typename disable_if, dummy* >::type=0): + thread(attributes const& attrs, F f + , typename disable_if, dummy* >::type=0 + ): thread_info(make_thread_info(f)) { start_thread(attrs); @@ -318,7 +323,7 @@ namespace boost } template - thread(attributes& attrs, BOOST_THREAD_RV_REF(F) f): + thread(attributes const& attrs, BOOST_THREAD_RV_REF(F) f): #ifdef BOOST_THREAD_USES_MOVE thread_info(make_thread_info(boost::move(f))) // todo : Add forward #else @@ -366,7 +371,17 @@ namespace boost { start_thread(); } + template + thread(attributes const& attrs, F&& f, Arg&& arg, Args&&... args) : + thread_info(make_thread_info( + thread_detail::decay_copy(boost::forward(f)), + thread_detail::decay_copy(boost::forward(arg)), + thread_detail::decay_copy(boost::forward(args))...) + ) + { + start_thread(attrs); + } #else template thread(F f,A1 a1,typename disable_if, dummy* >::type=0): @@ -730,16 +745,12 @@ namespace boost } #endif void thread::join() { - if (this_thread::get_id() == get_id()) - { - boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself")); - } - if (!join_noexcept()) - { -#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED - boost::throw_exception(thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")); -#endif - } + BOOST_THREAD_ASSERT_PRECONDITION( this_thread::get_id() != get_id(), + thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself") + ); + BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(), + thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable") + ); } #ifdef BOOST_THREAD_PLATFORM_PTHREAD @@ -748,10 +759,9 @@ namespace boost bool thread::do_try_join_until(uintmax_t timeout) #endif { - if (this_thread::get_id() == get_id()) - { - boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself")); - } + BOOST_THREAD_ASSERT_PRECONDITION( this_thread::get_id() != get_id(), + thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself") + ); bool res; if (do_try_join_until_noexcept(timeout, res)) { @@ -759,11 +769,10 @@ namespace boost } else { -#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED - boost::throw_exception(thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")); -#else - return false; -#endif + BOOST_THREAD_THROW_ELSE_RETURN( + thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable"), + false + ); } } diff --git a/include/boost/thread/externally_locked.hpp b/include/boost/thread/externally_locked.hpp index 59fd8f34..4d98fed5 100644 --- a/include/boost/thread/externally_locked.hpp +++ b/include/boost/thread/externally_locked.hpp @@ -87,19 +87,13 @@ namespace boost */ T& get(strict_lock& lk) { - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return obj_; } const T& get(strict_lock& lk) const { - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return obj_; } @@ -107,10 +101,7 @@ namespace boost T& get(nested_strict_lock& lk) { BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return obj_; } @@ -118,10 +109,7 @@ namespace boost const T& get(nested_strict_lock& lk) const { BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return obj_; } @@ -138,12 +126,9 @@ namespace boost BOOST_STATIC_ASSERT( (is_strict_lock::value)); /*< lk is a strict lock "sur parolle" >*/ BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP /*< define BOOST_THREAD_EXTERNALLY_LOCKED_NO_CHECK_OWNERSHIP if you don't want to check lock ownership >*/ - if (!lk.own_lock()) throw lock_error(); /*< run time check throw if no locked >*/ -#endif -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME - if (!lk.owns_lock(mtx_)) throw lock_error(); -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/ + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ + return obj_; } @@ -222,19 +207,13 @@ namespace boost */ T& get(strict_lock const& lk) { - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } const T& get(strict_lock const& lk) const { - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } @@ -242,10 +221,7 @@ namespace boost T& get(nested_strict_lock const& lk) { BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } @@ -253,10 +229,7 @@ namespace boost const T& get(nested_strict_lock const& lk) const { BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME /*< define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check lk check the same mtx >*/ - if (!lk.owns_lock(&mtx_)) throw lock_error(); /*< run time check throw if not locks the same >*/ -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } @@ -272,13 +245,8 @@ namespace boost BOOST_CONCEPT_ASSERT(( StrictLock )); BOOST_STATIC_ASSERT( (is_strict_lock::value)); /*< lk is a strict lock "sur parolle" >*/ BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP /*< define BOOST_THREAD_EXTERNALLY_LOCKED_NO_CHECK_OWNERSHIP if you don't want to check lock ownership >*/ - if (!lk.own_lock()) throw lock_error(); /*< run time check throw if no locked >*/ -#endif -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME - if (!lk.owns_lock(mtx_)) throw lock_error(); -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/ + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } @@ -294,13 +262,8 @@ namespace boost BOOST_CONCEPT_ASSERT(( StrictLock )); BOOST_STATIC_ASSERT( (is_strict_lock::value)); /*< lk is a strict lock "sur parolle" >*/ BOOST_STATIC_ASSERT( (is_same::value)); /*< that locks the same type >*/ - -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP /*< define BOOST_THREAD_EXTERNALLY_LOCKED_NO_CHECK_OWNERSHIP if you don't want to check lock ownership >*/ - if (!lk.own_lock()) throw lock_error(); /*< run time check throw if no locked >*/ -#endif -#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME - if (!lk.owns_lock(mtx_)) throw lock_error(); -#endif + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/ + BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/ return *obj_; } mutex_type* mutex() diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index e4a79082..8ed355d6 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -2903,7 +2903,7 @@ namespace boost BOOST_THREAD_FUTURE async(R(*f)()) { - return async(launch::any, f); + return BOOST_THREAD_MAKE_RV_REF(async(launch(launch::any), f)); } #endif @@ -2989,7 +2989,7 @@ namespace boost BOOST_THREAD_FUTURE::type> async(BOOST_THREAD_RV_REF(F) f) { - return async(launch::any, boost::forward(f)); + return async(launch(launch::any), boost::forward(f)); } diff --git a/include/boost/thread/scoped_thread.hpp b/include/boost/thread/scoped_thread.hpp index 032788a9..2759e38e 100644 --- a/include/boost/thread/scoped_thread.hpp +++ b/include/boost/thread/scoped_thread.hpp @@ -117,6 +117,11 @@ namespace boost { } +// explicit operator thread() +// { +// return boost::move(t_); +// } + /** * Move constructor. */ diff --git a/include/boost/thread/strict_lock.hpp b/include/boost/thread/strict_lock.hpp index 5c6711e3..bc7a2ed2 100644 --- a/include/boost/thread/strict_lock.hpp +++ b/include/boost/thread/strict_lock.hpp @@ -130,12 +130,10 @@ namespace boost nested_strict_lock(Lock& lk) : lk_(lk) /*< Store reference to lk >*/ { -#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED /*< Define BOOST_THREAD_DONT_CHECK_PRECONDITIONS if you don't want to check lk ownership >*/ - if (lk.mutex() == 0) - { - throw_exception( lock_error() ); - } -#endif + /*< Define BOOST_THREAD_DONT_CHECK_PRECONDITIONS if you don't want to check lk ownership >*/ + BOOST_THREAD_ASSERT_PRECONDITION( lk.mutex() != 0, + lock_error() + ); if (!lk.owns_lock()) lk.lock(); /*< ensures it is locked >*/ tmp_lk_ = move(lk); /*< Move ownership to temporary lk >*/ } diff --git a/include/boost/thread/win32/basic_recursive_mutex.hpp b/include/boost/thread/win32/basic_recursive_mutex.hpp index e259121a..cfdfa043 100644 --- a/include/boost/thread/win32/basic_recursive_mutex.hpp +++ b/include/boost/thread/win32/basic_recursive_mutex.hpp @@ -58,6 +58,7 @@ namespace boost recursion_count=1; } } +#if defined BOOST_THREAD_USES_DATETIME bool timed_lock(::boost::system_time const& target) { long const current_thread_id=win32::GetCurrentThreadId(); @@ -68,6 +69,7 @@ namespace boost { return timed_lock(get_system_time()+timeout); } +#endif #ifdef BOOST_THREAD_USES_CHRONO template @@ -114,6 +116,7 @@ namespace boost return false; } +#if defined BOOST_THREAD_USES_DATETIME bool try_timed_lock(long current_thread_id,::boost::system_time const& target) { if(mutex.timed_lock(target)) @@ -124,6 +127,7 @@ namespace boost } return false; } +#endif template bool try_timed_lock_until(long current_thread_id,TP const& target) { diff --git a/include/boost/thread/win32/basic_timed_mutex.hpp b/include/boost/thread/win32/basic_timed_mutex.hpp index 6a430774..5d85c70d 100644 --- a/include/boost/thread/win32/basic_timed_mutex.hpp +++ b/include/boost/thread/win32/basic_timed_mutex.hpp @@ -14,7 +14,9 @@ #include #include #include +#if defined BOOST_THREAD_USES_DATETIME #include +#endif #include #ifdef BOOST_THREAD_USES_CHRONO #include @@ -118,6 +120,7 @@ namespace boost } +#if defined BOOST_THREAD_USES_DATETIME bool timed_lock(::boost::system_time const& wait_until) { if(try_lock()) @@ -147,7 +150,6 @@ namespace boost return true; } - template bool timed_lock(Duration const& timeout) { @@ -158,7 +160,7 @@ namespace boost { return timed_lock(system_time(timeout)); } - +#endif #ifdef BOOST_THREAD_USES_CHRONO template bool try_lock_for(const chrono::duration& rel_time) diff --git a/include/boost/thread/win32/condition_variable.hpp b/include/boost/thread/win32/condition_variable.hpp index cffef568..5cf81fc9 100644 --- a/include/boost/thread/win32/condition_variable.hpp +++ b/include/boost/thread/win32/condition_variable.hpp @@ -11,7 +11,9 @@ #include #include #include +#if defined BOOST_THREAD_USES_DATETIME #include +#endif #include #include #include @@ -323,6 +325,7 @@ namespace boost } +#if defined BOOST_THREAD_USES_DATETIME bool timed_wait(unique_lock& m,boost::system_time const& abs_time) { return do_wait(m,abs_time); @@ -353,7 +356,7 @@ namespace boost { return do_wait(m,wait_duration.total_milliseconds(),pred); } - +#endif #ifdef BOOST_THREAD_USES_CHRONO template @@ -430,6 +433,7 @@ namespace boost while(!pred()) wait(m); } +#if defined BOOST_THREAD_USES_DATETIME template bool timed_wait(lock_type& m,boost::system_time const& abs_time) { @@ -465,6 +469,7 @@ namespace boost { return do_wait(m,wait_duration.total_milliseconds(),pred); } +#endif #ifdef BOOST_THREAD_USES_CHRONO template diff --git a/include/boost/thread/win32/recursive_mutex.hpp b/include/boost/thread/win32/recursive_mutex.hpp index 0d78c0f5..1f0f7f5e 100644 --- a/include/boost/thread/win32/recursive_mutex.hpp +++ b/include/boost/thread/win32/recursive_mutex.hpp @@ -12,6 +12,7 @@ #include #include +#include #if defined BOOST_THREAD_PROVIDES_NESTED_LOCKS #include #endif diff --git a/include/boost/thread/win32/shared_mutex.hpp b/include/boost/thread/win32/shared_mutex.hpp index fef2d5ba..94269489 100644 --- a/include/boost/thread/win32/shared_mutex.hpp +++ b/include/boost/thread/win32/shared_mutex.hpp @@ -136,12 +136,12 @@ namespace boost BOOST_VERIFY(timed_lock_shared(::boost::detail::get_system_time_sentinel())); } +#if defined BOOST_THREAD_USES_DATETIME template bool timed_lock_shared(TimeDuration const & relative_time) { return timed_lock_shared(get_system_time()+relative_time); } - bool timed_lock_shared(boost::system_time const& wait_until) { for(;;) @@ -220,6 +220,7 @@ namespace boost BOOST_ASSERT(res==0); } } +#endif #ifdef BOOST_THREAD_USES_CHRONO template diff --git a/include/boost/thread/xtime.hpp b/include/boost/thread/xtime.hpp index 1ca996fa..9c6a3596 100644 --- a/include/boost/thread/xtime.hpp +++ b/include/boost/thread/xtime.hpp @@ -9,6 +9,7 @@ #define BOOST_XTIME_WEK070601_HPP #include +#if defined BOOST_THREAD_USES_DATETIME #include #include @@ -88,5 +89,5 @@ inline int xtime_cmp(const xtime& xt1, const xtime& xt2) } // namespace boost #include - +#endif #endif //BOOST_XTIME_WEK070601_HPP diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index ed8b62e1..4620b16d 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -10,12 +10,13 @@ #include #include +#if defined BOOST_THREAD_USES_DATETIME #include +#endif #include #include #include #include -#include #include #ifdef __GLIBC__ @@ -422,6 +423,7 @@ namespace boost /// Workaround of DECCXX issue of incorrect template substitution template<> #endif +#if defined BOOST_THREAD_USES_DATETIME void sleep(const system_time& st) { detail::thread_data_base* const thread_info=detail::get_current_thread_data(); @@ -461,16 +463,19 @@ namespace boost } } } +#endif void yield() BOOST_NOEXCEPT { # if defined(BOOST_HAS_SCHED_YIELD) BOOST_VERIFY(!sched_yield()); # elif defined(BOOST_HAS_PTHREAD_YIELD) BOOST_VERIFY(!pthread_yield()); -# else +# elif defined BOOST_THREAD_USES_DATETIME xtime xt; xtime_get(&xt, TIME_UTC_); sleep(xt); +# else + sleep_for(chrono::milliseconds(0)); # endif } } diff --git a/src/pthread/timeconv.inl b/src/pthread/timeconv.inl index cab7c55a..d81f31ba 100644 --- a/src/pthread/timeconv.inl +++ b/src/pthread/timeconv.inl @@ -17,6 +17,7 @@ const int NANOSECONDS_PER_MILLISECOND = 1000000; const int MICROSECONDS_PER_SECOND = 1000000; const int NANOSECONDS_PER_MICROSECOND = 1000; +#if defined BOOST_THREAD_USES_DATETIME inline void to_time(int milliseconds, boost::xtime& xt) { int res = 0; @@ -33,7 +34,9 @@ inline void to_time(int milliseconds, boost::xtime& xt) xt.nsec -= NANOSECONDS_PER_SECOND; } } +#endif #if defined(BOOST_HAS_PTHREADS) +#if defined BOOST_THREAD_USES_DATETIME inline void to_timespec(const boost::xtime& xt, timespec& ts) { ts.tv_sec = static_cast(xt.sec); @@ -44,14 +47,27 @@ inline void to_timespec(const boost::xtime& xt, timespec& ts) ts.tv_nsec %= NANOSECONDS_PER_SECOND; } } - +#endif inline void to_time(int milliseconds, timespec& ts) { +#if defined BOOST_THREAD_USES_DATETIME boost::xtime xt; to_time(milliseconds, xt); to_timespec(xt, ts); +#else + ts.tv_sec += (milliseconds / MILLISECONDS_PER_SECOND); + ts.tv_nsec += ((milliseconds % MILLISECONDS_PER_SECOND) * + NANOSECONDS_PER_MILLISECOND); + + if (ts.tv_nsec >= NANOSECONDS_PER_SECOND) + { + ++ts.tv_sec; + ts.tv_nsec -= NANOSECONDS_PER_SECOND; + } +#endif } +#if defined BOOST_THREAD_USES_DATETIME inline void to_timespec_duration(const boost::xtime& xt, timespec& ts) { boost::xtime cur; @@ -82,7 +98,9 @@ inline void to_timespec_duration(const boost::xtime& xt, timespec& ts) } } #endif +#endif +#if defined BOOST_THREAD_USES_DATETIME inline void to_duration(boost::xtime xt, int& milliseconds) { boost::xtime cur; @@ -126,6 +144,7 @@ inline void to_microduration(boost::xtime xt, int& microseconds) NANOSECONDS_PER_MICROSECOND); } } +#endif } // Change Log: diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index c3a89d4e..61f70804 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -21,9 +21,9 @@ #include #include -#include +#if defined BOOST_THREAD_USES_DATETIME #include - +#endif #include #include #ifndef UNDER_CE @@ -344,17 +344,15 @@ namespace boost else { return false; -//#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED -// boost::throw_exception(thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")); -//#endif } } +#if defined BOOST_THREAD_USES_DATETIME bool thread::timed_join(boost::system_time const& wait_until) { return do_try_join_until(get_milliseconds_until(wait_until)); } - +#endif bool thread::do_try_join_until_noexcept(uintmax_t milli, bool& res) { detail::thread_data_ptr local_thread_info=(get_thread_info)(); @@ -372,9 +370,6 @@ namespace boost else { return false; -//#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED -// boost::throw_exception(thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")); -//#endif } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b2971cc9..8b5e15f6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -588,6 +588,9 @@ rule thread-compile-fail ( sources : reqs * : name ) explicit ts_ ; test-suite ts_ : + #[ thread-run test_7665.cpp ] + [ thread-run test_7666.cpp ] + #[ compile ../example/tes_is_function.cpp ] #[ thread-run ../example/unwrap.cpp ] ; diff --git a/test/condition_test_common.hpp b/test/condition_test_common.hpp index 38f77909..4aa114e0 100644 --- a/test/condition_test_common.hpp +++ b/test/condition_test_common.hpp @@ -2,7 +2,7 @@ #define CONDITION_TEST_COMMON_HPP // Copyright (C) 2007 Anthony Williams // -// Distributed under the Boost Software License, Version 1.0. (See accompanying +// Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include @@ -10,14 +10,14 @@ #include unsigned const timeout_seconds=5; - + struct wait_for_flag { boost::mutex mutex; boost::condition_variable cond_var; bool flag; unsigned woken; - + wait_for_flag(): flag(false),woken(0) {} @@ -25,11 +25,11 @@ struct wait_for_flag struct check_flag { bool const& flag; - + check_flag(bool const& flag_): flag(flag_) {} - + bool operator()() const { return flag; @@ -38,10 +38,10 @@ struct wait_for_flag void operator=(check_flag&); }; - + void wait_without_predicate() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); while(!flag) { cond_var.wait(lock); @@ -51,7 +51,7 @@ struct wait_for_flag void wait_with_predicate() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); cond_var.wait(lock,check_flag(flag)); if(flag) { @@ -62,8 +62,8 @@ struct wait_for_flag void timed_wait_without_predicate() { boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds); - - boost::mutex::scoped_lock lock(mutex); + + boost::unique_lock lock(mutex); while(!flag) { if(!cond_var.timed_wait(lock,timeout)) @@ -77,7 +77,7 @@ struct wait_for_flag void timed_wait_with_predicate() { boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds); - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); if(cond_var.timed_wait(lock,timeout,check_flag(flag)) && flag) { ++woken; @@ -85,7 +85,7 @@ struct wait_for_flag } void relative_timed_wait_with_predicate() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag) { ++woken; diff --git a/test/shared_mutex_locking_thread.hpp b/test/shared_mutex_locking_thread.hpp index 98a415b1..3b743235 100644 --- a/test/shared_mutex_locking_thread.hpp +++ b/test/shared_mutex_locking_thread.hpp @@ -37,15 +37,15 @@ public: unblocked_count_mutex(unblocked_count_mutex_), finish_mutex(finish_mutex_) {} - + void operator()() { // acquire lock lock_type lock(rw_mutex); - + // increment count to show we're unblocked { - boost::mutex::scoped_lock ublock(unblocked_count_mutex); + boost::unique_lock ublock(unblocked_count_mutex); ++unblocked_count; unblocked_condition.notify_one(); ++simultaneous_running_count; @@ -54,11 +54,11 @@ public: max_simultaneous_running=simultaneous_running_count; } } - + // wait to finish - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); { - boost::mutex::scoped_lock ublock(unblocked_count_mutex); + boost::unique_lock ublock(unblocked_count_mutex); --simultaneous_running_count; } } @@ -72,9 +72,9 @@ class simple_writing_thread boost::mutex& finish_mutex; boost::mutex& unblocked_mutex; unsigned& unblocked_count; - + void operator=(simple_writing_thread&); - + public: simple_writing_thread(boost::shared_mutex& rwm_, boost::mutex& finish_mutex_, @@ -83,17 +83,17 @@ public: rwm(rwm_),finish_mutex(finish_mutex_), unblocked_mutex(unblocked_mutex_),unblocked_count(unblocked_count_) {} - + void operator()() { boost::unique_lock lk(rwm); - + { - boost::mutex::scoped_lock ulk(unblocked_mutex); + boost::unique_lock ulk(unblocked_mutex); ++unblocked_count; } - - boost::mutex::scoped_lock flk(finish_mutex); + + boost::unique_lock flk(finish_mutex); } }; @@ -103,9 +103,9 @@ class simple_reading_thread boost::mutex& finish_mutex; boost::mutex& unblocked_mutex; unsigned& unblocked_count; - + void operator=(simple_reading_thread&); - + public: simple_reading_thread(boost::shared_mutex& rwm_, boost::mutex& finish_mutex_, @@ -114,17 +114,17 @@ public: rwm(rwm_),finish_mutex(finish_mutex_), unblocked_mutex(unblocked_mutex_),unblocked_count(unblocked_count_) {} - + void operator()() { boost::shared_lock lk(rwm); - + { - boost::mutex::scoped_lock ulk(unblocked_mutex); + boost::unique_lock ulk(unblocked_mutex); ++unblocked_count; } - - boost::mutex::scoped_lock flk(finish_mutex); + + boost::unique_lock flk(finish_mutex); } }; diff --git a/test/test_2309.cpp b/test/test_2309.cpp index 70175ac6..78fab44c 100755 --- a/test/test_2309.cpp +++ b/test/test_2309.cpp @@ -24,18 +24,18 @@ } catch (boost::thread_interrupted& interrupt) { - boost::mutex::scoped_lock lock(mutex_); + boost::unique_lock lock(mutex_); cerr << "Thread " << boost::this_thread::get_id() << " got interrupted" << endl; throw(interrupt); } catch (std::exception& e) { - boost::mutex::scoped_lock lock(mutex_); + boost::unique_lock lock(mutex_); cerr << "Thread " << boost::this_thread::get_id() << " caught std::exception" << e.what() << endl; } catch (...) { - boost::mutex::scoped_lock lock(mutex_); + boost::unique_lock lock(mutex_); cerr << "Thread " << boost::this_thread::get_id() << " caught something else" << endl; } } diff --git a/test/test_3628.cpp b/test/test_3628.cpp index b15cb760..02914d81 100644 --- a/test/test_3628.cpp +++ b/test/test_3628.cpp @@ -27,7 +27,7 @@ void ThreadFuncWaiter() for (int j = 0; j < 10; j++) { { - boost::recursive_mutex::scoped_lock lockMtx(theMutex); + boost::unique_lock lockMtx(theMutex); theConditions.push_back(&con1); cout << "Added " << boost::this_thread::get_id() << " " << &con1 << endl; @@ -56,7 +56,7 @@ void ThreadFuncNotifier() for (int j = 0; j < 70; j++) { { - boost::recursive_mutex::scoped_lock lockMtx(theMutex); + boost::unique_lock lockMtx(theMutex); cout << " lk(mtx); //const bool res = (void)cv.timed_wait(lk, from_time_t(wait_time)); end_time = ::time(0); diff --git a/test/test_6174.cpp b/test/test_6174.cpp index cd7ed4e7..250764f9 100644 --- a/test/test_6174.cpp +++ b/test/test_6174.cpp @@ -4,6 +4,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#define BOOST_THREAD_VERSION 3 #include #include diff --git a/test/test_7571.cpp b/test/test_7571.cpp index 1bee85db..e272c2ad 100644 --- a/test/test_7571.cpp +++ b/test/test_7571.cpp @@ -19,7 +19,7 @@ public: ItemKeeper() { } void doSomething() { - boost::mutex::scoped_lock scoped_lock(mutex); + boost::unique_lock scoped_lock(mutex); int counts = MAX_COUNTS; while (counts--); } diff --git a/test/test_7665.cpp b/test/test_7665.cpp new file mode 100644 index 00000000..b20ac4ed --- /dev/null +++ b/test/test_7665.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2010 Vicente Botet +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_THREAD_VERSION 2 + +#include +#include + +void thread() +{ + std::cout << "Sleeping for 10 seconds - change time\n"; + boost::this_thread::sleep_for(boost::chrono::seconds(30)); + std::cout << "Ended\n"; + //while (1) ; // Never quit +} + +boost::thread example(thread); + +int main() +{ + std::cout << "Main thread START\n"; + boost::this_thread::sleep_for(boost::chrono::seconds(30)); + std::cout << "Main thread END\n"; + //while (1) ; // Never quit + example.join(); + return 0; +} + diff --git a/test/test_barrier.cpp b/test/test_barrier.cpp index 5732b5f6..4a8b9b17 100644 --- a/test/test_barrier.cpp +++ b/test/test_barrier.cpp @@ -28,7 +28,7 @@ void barrier_thread() { if (gen_barrier.wait()) { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); global_parameter++; } } diff --git a/test/test_condition.cpp b/test/test_condition.cpp index e7d428ef..e70d3b5b 100644 --- a/test/test_condition.cpp +++ b/test/test_condition.cpp @@ -30,7 +30,7 @@ struct condition_test_data void condition_test_thread(condition_test_data* data) { - boost::mutex::scoped_lock lock(data->mutex); + boost::unique_lock lock(data->mutex); BOOST_CHECK(lock ? true : false); while (!(data->notified > 0)) data->condition.wait(lock); @@ -53,7 +53,7 @@ private: void condition_test_waits(condition_test_data* data) { - boost::mutex::scoped_lock lock(data->mutex); + boost::unique_lock lock(data->mutex); BOOST_CHECK(lock ? true : false); // Test wait. @@ -107,7 +107,7 @@ void do_test_condition_waits() boost::thread thread(bind(&condition_test_waits, &data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); BOOST_CHECK(lock ? true : false); boost::thread::sleep(delay(1)); diff --git a/test/test_condition_notify_all.cpp b/test/test_condition_notify_all.cpp index 0303ab6d..16653fdb 100644 --- a/test/test_condition_notify_all.cpp +++ b/test/test_condition_notify_all.cpp @@ -30,7 +30,7 @@ void do_test_condition_notify_all_wakes_from_wait() } { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_all(); } @@ -59,7 +59,7 @@ void do_test_condition_notify_all_wakes_from_wait_with_predicate() } { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_all(); } @@ -88,7 +88,7 @@ void do_test_condition_notify_all_wakes_from_timed_wait() } { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_all(); } @@ -117,7 +117,7 @@ void do_test_condition_notify_all_wakes_from_timed_wait_with_predicate() } { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_all(); } @@ -146,7 +146,7 @@ void do_test_condition_notify_all_wakes_from_relative_timed_wait_with_predicate( } { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_all(); } @@ -169,7 +169,7 @@ namespace void wait_for_condvar_and_increase_count() { - boost::mutex::scoped_lock lk(multiple_wake_mutex); + boost::unique_lock lk(multiple_wake_mutex); multiple_wake_cond.wait(lk); ++multiple_wake_count; } @@ -193,7 +193,7 @@ void do_test_notify_all_following_notify_one_wakes_all_threads() boost::this_thread::sleep(boost::posix_time::milliseconds(200)); { - boost::mutex::scoped_lock lk(multiple_wake_mutex); + boost::unique_lock lk(multiple_wake_mutex); BOOST_CHECK(multiple_wake_count==3); } diff --git a/test/test_condition_notify_one.cpp b/test/test_condition_notify_one.cpp index b6593ae8..9ffabf4e 100644 --- a/test/test_condition_notify_one.cpp +++ b/test/test_condition_notify_one.cpp @@ -21,7 +21,7 @@ void do_test_condition_notify_one_wakes_from_wait() boost::thread thread(bind(&wait_for_flag::wait_without_predicate, data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_one(); } @@ -37,7 +37,7 @@ void do_test_condition_notify_one_wakes_from_wait_with_predicate() boost::thread thread(bind(&wait_for_flag::wait_with_predicate, data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_one(); } @@ -53,7 +53,7 @@ void do_test_condition_notify_one_wakes_from_timed_wait() boost::thread thread(bind(&wait_for_flag::timed_wait_without_predicate, data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_one(); } @@ -69,7 +69,7 @@ void do_test_condition_notify_one_wakes_from_timed_wait_with_predicate() boost::thread thread(bind(&wait_for_flag::timed_wait_with_predicate, data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_one(); } @@ -85,7 +85,7 @@ void do_test_condition_notify_one_wakes_from_relative_timed_wait_with_predicate( boost::thread thread(bind(&wait_for_flag::relative_timed_wait_with_predicate, data)); { - boost::mutex::scoped_lock lock(data.mutex); + boost::unique_lock lock(data.mutex); data.flag=true; data.cond_var.notify_one(); } @@ -102,7 +102,7 @@ namespace void wait_for_condvar_and_increase_count() { - boost::mutex::scoped_lock lk(multiple_wake_mutex); + boost::unique_lock lk(multiple_wake_mutex); multiple_wake_cond.wait(lk); ++multiple_wake_count; } @@ -126,7 +126,7 @@ void do_test_multiple_notify_one_calls_wakes_multiple_threads() boost::this_thread::sleep(boost::posix_time::milliseconds(200)); { - boost::mutex::scoped_lock lk(multiple_wake_mutex); + boost::unique_lock lk(multiple_wake_mutex); BOOST_CHECK(multiple_wake_count==3); } diff --git a/test/test_condition_timed_wait_times_out.cpp b/test/test_condition_timed_wait_times_out.cpp index 70fbbf3b..b53c60e9 100644 --- a/test/test_condition_timed_wait_times_out.cpp +++ b/test/test_condition_timed_wait_times_out.cpp @@ -29,7 +29,7 @@ void do_test_timed_wait_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); boost::system_time const timeout=start+delay; @@ -45,7 +45,7 @@ void do_test_timed_wait_with_predicate_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); boost::system_time const timeout=start+delay; @@ -62,7 +62,7 @@ void do_test_relative_timed_wait_with_predicate_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); bool const res=cond.timed_wait(lock,delay,fake_predicate); @@ -78,7 +78,7 @@ void do_test_timed_wait_relative_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); while(cond.timed_wait(lock,delay)) {} @@ -93,7 +93,7 @@ void do_test_cv_any_timed_wait_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); boost::system_time const timeout=start+delay; @@ -109,7 +109,7 @@ void do_test_cv_any_timed_wait_with_predicate_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); boost::system_time const timeout=start+delay; @@ -126,7 +126,7 @@ void do_test_cv_any_relative_timed_wait_with_predicate_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); bool const res=cond.timed_wait(lock,delay,fake_predicate); @@ -142,7 +142,7 @@ void do_test_cv_any_timed_wait_relative_times_out() boost::mutex m; boost::posix_time::seconds const delay(timeout_seconds); - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); boost::system_time const start=boost::get_system_time(); while(cond.timed_wait(lock,delay)) {} diff --git a/test/test_generic_locks.cpp b/test/test_generic_locks.cpp index 346f73af..91203f3f 100644 --- a/test/test_generic_locks.cpp +++ b/test/test_generic_locks.cpp @@ -15,7 +15,7 @@ void test_lock_two_uncontended() { boost::mutex m1,m2; - boost::mutex::scoped_lock l1(m1,boost::defer_lock), + boost::unique_lock l1(m1,boost::defer_lock), l2(m2,boost::defer_lock); BOOST_CHECK(!l1.owns_lock()); @@ -39,7 +39,7 @@ struct wait_data void wait() { - boost::mutex::scoped_lock l(m); + boost::unique_lock l(m); while(!flag) { cond.wait(l); @@ -51,7 +51,7 @@ struct wait_data { boost::system_time const target=boost::get_system_time()+d; - boost::mutex::scoped_lock l(m); + boost::unique_lock l(m); while(!flag) { if(!cond.timed_wait(l,target)) @@ -64,7 +64,7 @@ struct wait_data void signal() { - boost::mutex::scoped_lock l(m); + boost::unique_lock l(m); flag=true; cond.notify_all(); } @@ -83,7 +83,7 @@ void lock_mutexes_slowly(boost::mutex* m1,boost::mutex* m2,wait_data* locked,wai void lock_pair(boost::mutex* m1,boost::mutex* m2) { boost::lock(*m1,*m2); - boost::mutex::scoped_lock l1(*m1,boost::adopt_lock), + boost::unique_lock l1(*m1,boost::adopt_lock), l2(*m2,boost::adopt_lock); } @@ -129,7 +129,7 @@ void test_lock_five_uncontended() { boost::mutex m1,m2,m3,m4,m5; - boost::mutex::scoped_lock l1(m1,boost::defer_lock), + boost::unique_lock l1(m1,boost::defer_lock), l2(m2,boost::defer_lock), l3(m3,boost::defer_lock), l4(m4,boost::defer_lock), diff --git a/test/test_lock_concept.cpp b/test/test_lock_concept.cpp index 8665f6e5..21f822b2 100644 --- a/test/test_lock_concept.cpp +++ b/test/test_lock_concept.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -66,7 +67,7 @@ struct test_initially_unlocked_if_other_thread_has_lock try { { - boost::mutex::scoped_lock lk(done_mutex); + boost::unique_lock lk(done_mutex); BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2), boost::bind(&this_type::is_done,this))); BOOST_CHECK(!locked); @@ -124,7 +125,7 @@ struct test_initially_unlocked_with_try_lock_if_other_thread_has_unique_lock try { { - boost::mutex::scoped_lock lk(done_mutex); + boost::unique_lock lk(done_mutex); BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2), boost::bind(&this_type::is_done,this))); BOOST_CHECK(!locked); @@ -182,7 +183,7 @@ struct test_initially_locked_if_other_thread_has_shared_lock try { { - boost::mutex::scoped_lock lk(done_mutex); + boost::unique_lock lk(done_mutex); BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2), boost::bind(&this_type::is_done,this))); BOOST_CHECK(locked); @@ -307,7 +308,7 @@ struct test_unlocked_after_try_lock_if_other_thread_has_lock try { { - boost::mutex::scoped_lock lk(done_mutex); + boost::unique_lock lk(done_mutex); BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2), boost::bind(&this_type::is_done,this))); BOOST_CHECK(!locked); diff --git a/test/test_mutex.cpp b/test/test_mutex.cpp index 28bed634..36ea6d18 100644 --- a/test/test_mutex.cpp +++ b/test/test_mutex.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -154,7 +155,7 @@ struct test_lock_times_out_if_other_thread_has_lock try { { - boost::mutex::scoped_lock lk(done_mutex); + boost::unique_lock lk(done_mutex); BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2), boost::bind(&this_type::is_done,this))); BOOST_CHECK(!locked); diff --git a/test/test_once.cpp b/test/test_once.cpp index dc3f332e..43afbbd9 100644 --- a/test/test_once.cpp +++ b/test/test_once.cpp @@ -21,7 +21,7 @@ boost::mutex m; void initialize_variable() { // ensure that if multiple threads get in here, they are serialized, so we can see the effect - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); ++var_to_init; } @@ -39,7 +39,7 @@ void call_once_thread() break; } } - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); BOOST_CHECK_EQUAL(my_once_value, 1); } @@ -79,7 +79,7 @@ struct increment_value void operator()() const { - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); ++(*value); } }; @@ -98,7 +98,7 @@ void call_once_with_functor() break; } } - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); BOOST_CHECK_EQUAL(my_once_value, 1); } @@ -137,7 +137,7 @@ struct throw_before_third_pass void operator()() const { - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); ++pass_counter; if(pass_counter<3) { @@ -158,7 +158,7 @@ void call_once_with_exception() } catch(throw_before_third_pass::my_exception) { - boost::mutex::scoped_lock lock(m); + boost::unique_lock lock(m); ++exception_counter; } } diff --git a/test/test_shared_mutex.cpp b/test/test_shared_mutex.cpp index 0eb9ed96..4ed0bb2d 100644 --- a/test/test_shared_mutex.cpp +++ b/test/test_shared_mutex.cpp @@ -14,7 +14,7 @@ #define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \ { \ - boost::mutex::scoped_lock lock(mutex_name); \ + boost::unique_lock lock(mutex_name); \ BOOST_CHECK_EQUAL(value,expected_value); \ } @@ -31,7 +31,7 @@ void test_multiple_readers() boost::mutex unblocked_count_mutex; boost::condition_variable unblocked_condition; boost::mutex finish_mutex; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); try { @@ -42,7 +42,7 @@ void test_multiple_readers() } { - boost::mutex::scoped_lock lk(unblocked_count_mutex); + boost::unique_lock lk(unblocked_count_mutex); while(unblocked_count finish_lock(finish_mutex); try { @@ -118,7 +118,7 @@ void test_reader_blocks_writer() boost::mutex unblocked_count_mutex; boost::condition_variable unblocked_condition; boost::mutex finish_mutex; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); try { @@ -126,7 +126,7 @@ void test_reader_blocks_writer() pool.create_thread(locking_thread >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition, finish_mutex,simultaneous_running_count,max_simultaneous_running)); { - boost::mutex::scoped_lock lk(unblocked_count_mutex); + boost::unique_lock lk(unblocked_count_mutex); while(unblocked_count<1) { unblocked_condition.wait(lk); @@ -165,7 +165,7 @@ void test_unlocking_writer_unblocks_all_readers() boost::mutex unblocked_count_mutex; boost::condition_variable unblocked_condition; boost::mutex finish_mutex; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); unsigned const reader_count=10; @@ -182,7 +182,7 @@ void test_unlocking_writer_unblocks_all_readers() write_lock.unlock(); { - boost::mutex::scoped_lock lk(unblocked_count_mutex); + boost::unique_lock lk(unblocked_count_mutex); while(unblocked_count finish_reading_lock(finish_reading_mutex); boost::mutex finish_writing_mutex; - boost::mutex::scoped_lock finish_writing_lock(finish_writing_mutex); + boost::unique_lock finish_writing_lock(finish_writing_mutex); unsigned const reader_count=10; unsigned const writer_count=10; @@ -238,7 +238,7 @@ void test_unlocking_last_reader_only_unblocks_one_writer() finish_writing_mutex,simultaneous_running_writers,max_simultaneous_writers)); } { - boost::mutex::scoped_lock lk(unblocked_count_mutex); + boost::unique_lock lk(unblocked_count_mutex); while(unblocked_count lk(unblocked_count_mutex); while(unblocked_count<(reader_count+1)) { unblocked_condition.wait(lk); diff --git a/test/test_shared_mutex_part_2.cpp b/test/test_shared_mutex_part_2.cpp index 828c02b5..e6c47690 100644 --- a/test/test_shared_mutex_part_2.cpp +++ b/test/test_shared_mutex_part_2.cpp @@ -13,7 +13,7 @@ #define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \ { \ - boost::mutex::scoped_lock lock(mutex_name); \ + boost::unique_lock lock(mutex_name); \ BOOST_CHECK_EQUAL(value,expected_value); \ } @@ -40,11 +40,11 @@ public: boost::upgrade_lock lk(rwm); { - boost::mutex::scoped_lock ulk(unblocked_mutex); + boost::unique_lock ulk(unblocked_mutex); ++unblocked_count; } - boost::mutex::scoped_lock flk(finish_mutex); + boost::unique_lock flk(finish_mutex); } }; @@ -62,7 +62,7 @@ void test_only_one_upgrade_lock_permitted() boost::mutex unblocked_count_mutex; boost::condition_variable unblocked_condition; boost::mutex finish_mutex; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); try { @@ -102,7 +102,7 @@ void test_can_lock_upgrade_if_currently_locked_shared() boost::mutex unblocked_count_mutex; boost::condition_variable unblocked_condition; boost::mutex finish_mutex; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); unsigned const reader_count=10; @@ -117,7 +117,7 @@ void test_can_lock_upgrade_if_currently_locked_shared() pool.create_thread(locking_thread >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition, finish_mutex,simultaneous_running_count,max_simultaneous_running)); { - boost::mutex::scoped_lock lk(unblocked_count_mutex); + boost::unique_lock lk(unblocked_count_mutex); while(unblocked_count<(reader_count+1)) { unblocked_condition.wait(lk); @@ -155,7 +155,7 @@ void test_if_other_thread_has_write_lock_try_lock_shared_returns_false() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep(boost::posix_time::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -178,7 +178,7 @@ void test_if_other_thread_has_write_lock_try_lock_upgrade_returns_false() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep(boost::posix_time::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -223,7 +223,7 @@ void test_if_other_thread_has_shared_lock_try_lock_shared_returns_true() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -246,7 +246,7 @@ void test_if_other_thread_has_shared_lock_try_lock_upgrade_returns_true() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -269,7 +269,7 @@ void test_if_other_thread_has_upgrade_lock_try_lock_upgrade_returns_false() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_upgrade_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep(boost::posix_time::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); diff --git a/test/test_shared_mutex_timed_locks.cpp b/test/test_shared_mutex_timed_locks.cpp index 5d407513..7f2a242e 100644 --- a/test/test_shared_mutex_timed_locks.cpp +++ b/test/test_shared_mutex_timed_locks.cpp @@ -13,7 +13,7 @@ #define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \ { \ - boost::mutex::scoped_lock lock(mutex_name); \ + boost::unique_lock lock(mutex_name); \ BOOST_CHECK_EQUAL(value,expected_value); \ } @@ -24,7 +24,7 @@ void test_timed_lock_shared_times_out_if_write_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -89,7 +89,7 @@ void test_timed_lock_shared_succeeds_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -125,7 +125,7 @@ void test_timed_lock_times_out_if_write_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -190,7 +190,7 @@ void test_timed_lock_times_out_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::thread::sleep(delay(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -226,7 +226,7 @@ void test_timed_lock_times_out_but_read_lock_succeeds_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep(boost::posix_time::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); diff --git a/test/test_shared_mutex_timed_locks_chrono.cpp b/test/test_shared_mutex_timed_locks_chrono.cpp index e3e98ffa..afa04868 100644 --- a/test/test_shared_mutex_timed_locks_chrono.cpp +++ b/test/test_shared_mutex_timed_locks_chrono.cpp @@ -15,7 +15,7 @@ #define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \ { \ - boost::mutex::scoped_lock lock(mutex_name); \ + boost::unique_lock lock(mutex_name); \ BOOST_CHECK_EQUAL(value,expected_value); \ } @@ -26,7 +26,7 @@ void test_timed_lock_shared_times_out_if_write_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep_for(boost::chrono::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -91,7 +91,7 @@ void test_timed_lock_shared_succeeds_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep_for(boost::chrono::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -127,7 +127,7 @@ void test_timed_lock_times_out_if_write_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread writer(simple_writing_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep_for(boost::chrono::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -192,7 +192,7 @@ void test_timed_lock_times_out_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep_for(boost::chrono::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); @@ -228,7 +228,7 @@ void test_timed_lock_times_out_but_read_lock_succeeds_if_read_lock_held() boost::mutex finish_mutex; boost::mutex unblocked_mutex; unsigned unblocked_count=0; - boost::mutex::scoped_lock finish_lock(finish_mutex); + boost::unique_lock finish_lock(finish_mutex); boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count)); boost::this_thread::sleep_for(boost::chrono::seconds(1)); CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u); diff --git a/test/test_thread.cpp b/test/test_thread.cpp index 1c71e950..09717f4d 100644 --- a/test/test_thread.cpp +++ b/test/test_thread.cpp @@ -77,7 +77,7 @@ void test_id_comparison() void interruption_point_thread(boost::mutex* m,bool* failed) { - boost::mutex::scoped_lock lk(*m); + boost::unique_lock lk(*m); boost::this_thread::interruption_point(); *failed=true; } @@ -86,7 +86,7 @@ void do_test_thread_interrupts_at_interruption_point() { boost::mutex m; bool failed=false; - boost::mutex::scoped_lock lk(m); + boost::unique_lock lk(m); boost::thread thrd(boost::bind(&interruption_point_thread,&m,&failed)); thrd.interrupt(); lk.unlock(); @@ -101,7 +101,7 @@ void test_thread_interrupts_at_interruption_point() void disabled_interruption_point_thread(boost::mutex* m,bool* failed) { - boost::mutex::scoped_lock lk(*m); + boost::unique_lock lk(*m); boost::this_thread::disable_interruption dc; boost::this_thread::interruption_point(); *failed=false; @@ -111,7 +111,7 @@ void do_test_thread_no_interrupt_if_interrupts_disabled_at_interruption_point() { boost::mutex m; bool failed=true; - boost::mutex::scoped_lock lk(m); + boost::unique_lock lk(m); boost::thread thrd(boost::bind(&disabled_interruption_point_thread,&m,&failed)); thrd.interrupt(); lk.unlock(); @@ -165,7 +165,7 @@ struct long_running_thread void operator()() { - boost::mutex::scoped_lock lk(mut); + boost::unique_lock lk(mut); while(!done) { cond.wait(lk); @@ -184,7 +184,7 @@ void do_test_timed_join() BOOST_CHECK(!joined); BOOST_CHECK(thrd.joinable()); { - boost::mutex::scoped_lock lk(f.mut); + boost::unique_lock lk(f.mut); f.done=true; f.cond.notify_one(); } diff --git a/test/test_thread_launching.cpp b/test/test_thread_launching.cpp index ee309e42..1137f1de 100644 --- a/test/test_thread_launching.cpp +++ b/test/test_thread_launching.cpp @@ -2,6 +2,9 @@ // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_THREAD_VERSION 3 + #include #include #include diff --git a/test/test_thread_mf.cpp b/test/test_thread_mf.cpp index aa5a5dc1..1d9145f7 100644 --- a/test/test_thread_mf.cpp +++ b/test/test_thread_mf.cpp @@ -5,6 +5,7 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // +#define BOOST_THREAD_VERSION 3 #include #include diff --git a/test/test_tss.cpp b/test/test_tss.cpp index c1728469..48f1c358 100644 --- a/test/test_tss.cpp +++ b/test/test_tss.cpp @@ -34,14 +34,14 @@ struct tss_value_t { tss_value_t() { - boost::mutex::scoped_lock lock(tss_mutex); + boost::unique_lock lock(tss_mutex); ++tss_instances; ++tss_total; value = 0; } ~tss_value_t() { - boost::mutex::scoped_lock lock(tss_mutex); + boost::unique_lock lock(tss_mutex); --tss_instances; } int value; @@ -59,7 +59,7 @@ void test_tss_thread() // be thread safe. Must evaluate further. if (n != i) { - boost::mutex::scoped_lock lock(check_mutex); + boost::unique_lock lock(check_mutex); BOOST_CHECK_EQUAL(n, i); } ++n; diff --git a/test/test_xtime.cpp b/test/test_xtime.cpp index 447cb619..ed66b41b 100644 --- a/test/test_xtime.cpp +++ b/test/test_xtime.cpp @@ -88,7 +88,7 @@ void test_xtime_condvar_backwards_compatibility() boost::condition_variable_any cond_any; boost::mutex m; - boost::mutex::scoped_lock lk(m); + boost::unique_lock lk(m); cond.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10))); cond.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)),predicate); cond_any.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10))); diff --git a/test/threads/container/thread_ptr_list_pass.cpp b/test/threads/container/thread_ptr_list_pass.cpp index 3bf58110..e1266dcb 100644 --- a/test/threads/container/thread_ptr_list_pass.cpp +++ b/test/threads/container/thread_ptr_list_pass.cpp @@ -33,7 +33,7 @@ void join_all(TC & tc) void increment_count() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); std::cout << "count = " << ++count << std::endl; } diff --git a/test/threads/container/thread_vector_pass.cpp b/test/threads/container/thread_vector_pass.cpp index 1d66941f..fd561ab3 100644 --- a/test/threads/container/thread_vector_pass.cpp +++ b/test/threads/container/thread_vector_pass.cpp @@ -40,7 +40,7 @@ void interrupt_all(TC & tc) void increment_count() { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); std::cout << "count = " << ++count << std::endl; } diff --git a/test/util.inl b/test/util.inl index b85fbb08..010dc50e 100644 --- a/test/util.inl +++ b/test/util.inl @@ -74,7 +74,7 @@ public: void start() { if (type != use_sleep_only) { - boost::mutex::scoped_lock lock(mutex); done = false; + boost::unique_lock lock(mutex); done = false; } else { done = false; } @@ -82,7 +82,7 @@ public: void finish() { if (type != use_sleep_only) { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); done = true; if (type == use_condition) cond.notify_one(); @@ -96,7 +96,7 @@ public: if (type != use_condition) boost::thread::sleep(xt); if (type != use_sleep_only) { - boost::mutex::scoped_lock lock(mutex); + boost::unique_lock lock(mutex); while (type == use_condition && !done) { if (!cond.timed_wait(lock, xt)) break;