2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-19 04:42:13 +00:00

Thread: deprecate nested scoped locks and DateTime based timed fuctions

[SVN r81279]
This commit is contained in:
Vicente J. Botet Escriba
2012-11-10 10:25:33 +00:00
parent 5c5c818bc5
commit 0cd8326f21
58 changed files with 584 additions and 345 deletions

View File

@@ -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<R> is deprecated, use instead packaged_task<R()>. See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK
* C++11 compliance: packaged_task<R> is deprecated, use instead packaged_task<R()>.
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:

View File

@@ -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.

View File

@@ -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__<R> 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<typename F>
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<R&>::set_value_at_thread_exit(R& r);
void promise<void>::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<typename F>
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<typename F>
@@ -1281,8 +1398,12 @@ as invoking `f`.]]
[[Effects:] [Constructs a new __packaged_task__ with `boost::forward<F>(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();

View File

@@ -7,13 +7,13 @@
#include <iostream>
#include <vector>
#include <boost/utility.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/thread.hpp>
class bounded_buffer : private boost::noncopyable
{
public:
typedef boost::mutex::scoped_lock lock;
typedef boost::unique_lock<boost::mutex> 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<int> 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<boost::mutex> 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<boost::mutex> io_lock(io_mutex);
std::cout << "received: " << n << std::endl;
}
} while (n != -1); // -1 indicates end of buffer

View File

@@ -15,7 +15,7 @@ boost::future<int> compute(int x)
if (x == 0) return boost::make_future(0);
if (x < 0) return boost::make_future(-1);
//boost::future<int> f1 = boost::async([]() { return x+1; });
boost::future<int> f1 = boost::async(p1);
boost::future<int> f1 = boost::async(boost::launch::async, p1);
return boost::move(f1);
}
boost::shared_future<int> shared_compute(int x)

View File

@@ -6,7 +6,7 @@
#include <vector>
#include <iostream>
#include <boost/thread/condition.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>
@@ -20,7 +20,7 @@ template <typename M>
class buffer_t
{
public:
typedef typename M::scoped_lock scoped_lock;
typedef boost::unique_lock<M> 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<boost::mutex> 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<boost::mutex> 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<int> buf;
};

View File

@@ -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 <boost/thread/mutex.hpp>
@@ -16,7 +16,7 @@ public:
counter() : count(0) { }
int increment() {
boost::mutex::scoped_lock scoped_lock(mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> scoped_lock(io_mutex);
std::cout << "count == " << i << std::endl;
}

View File

@@ -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 <boost/thread/recursive_mutex.hpp>
@@ -14,12 +14,12 @@ public:
counter() : count(0) { }
int add(int val) {
boost::recursive_mutex::scoped_lock scoped_lock(mutex);
boost::unique_lock<boost::recursive_mutex> scoped_lock(mutex);
count += val;
return count;
}
int increment() {
boost::recursive_mutex::scoped_lock scoped_lock(mutex);
boost::unique_lock<boost::recursive_mutex> scoped_lock(mutex);
return add(1);
}

View File

@@ -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 <iostream>
//#include <string>
#include <boost/thread/scoped_thread.hpp>
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;
}

View File

@@ -25,18 +25,18 @@ public:
void get(int id)
{
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> lock(m_mutex);
while (m_chickens == 0)
{
{
boost::mutex::scoped_lock lk(iomx);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(m_mutex);
{
boost::mutex::scoped_lock lk(iomx);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(iomx);
std::cout << "(" << clock() << ") Chef: starting ..." << std::endl;
}
for (;;)
{
{
boost::mutex::scoped_lock lock(iomx);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lk(iomx);
std::cout << "(" << clock() << ") Phil" << m_id
<< ": mmm ... that's good ..." << std::endl;
}

View File

@@ -41,7 +41,7 @@ char* player_name(int state)
void player(void* param)
{
boost::mutex::scoped_lock lock(mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(mutex);
std::cout << "---Noise OFF..." << std::endl;
state = GAME_OVER;
cond.notify_all();

View File

@@ -12,7 +12,7 @@ boost::mutex mutex;
void increment_count()
{
boost::mutex::scoped_lock lock(mutex);
boost::unique_lock<boost::mutex> lock(mutex);
std::cout << "count = " << ++count << std::endl;
}

View File

@@ -12,6 +12,7 @@
#include <boost/throw_exception.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/condition_variable.hpp>
#include <string>
#include <stdexcept>
@@ -33,7 +34,7 @@ namespace boost
bool wait()
{
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> lock(m_mutex);
unsigned int gen = m_generation;
if (--m_count == 0)

View File

@@ -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"

View File

@@ -14,7 +14,9 @@
#endif
#include <boost/thread/detail/move.hpp>
#include <boost/thread/mutex.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/thread/xtime.hpp>
#endif
#include <boost/thread/detail/thread_heap_alloc.hpp>
#include <boost/thread/detail/make_tuple_indices.hpp>
#include <boost/thread/detail/invoke.hpp>
@@ -257,7 +259,7 @@ namespace boost
class F
>
explicit thread(BOOST_THREAD_RV_REF(F) f
, typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0
//, typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0
):
thread_info(make_thread_info(thread_detail::decay_copy(boost::forward<F>(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>(f))))
{
start_thread(attrs);
@@ -281,7 +283,7 @@ namespace boost
start_thread();
}
template <class F>
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 <class F>
explicit thread(F f
, typename disable_if_c<
boost::is_convertible<F&,BOOST_THREAD_RV_REF(F)>::value || is_same<typename decay<F>::type, thread>::value,
dummy* >::type=0):
boost::is_convertible<F&,BOOST_THREAD_RV_REF(F)>::value
//|| is_same<typename decay<F>::type, thread>::value
, dummy* >::type=0
):
thread_info(make_thread_info(f))
{
start_thread();
}
template <class F>
thread(attributes& attrs, F f
, typename disable_if<boost::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0):
thread(attributes const& attrs, F f
, typename disable_if<boost::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0
):
thread_info(make_thread_info(f))
{
start_thread(attrs);
@@ -318,7 +323,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):
#ifdef BOOST_THREAD_USES_MOVE
thread_info(make_thread_info(boost::move<F>(f))) // todo : Add forward
#else
@@ -366,7 +371,17 @@ namespace boost
{
start_thread();
}
template <class F, class Arg, class ...Args>
thread(attributes const& attrs, F&& f, Arg&& arg, Args&&... args) :
thread_info(make_thread_info(
thread_detail::decay_copy(boost::forward<F>(f)),
thread_detail::decay_copy(boost::forward<Arg>(arg)),
thread_detail::decay_copy(boost::forward<Args>(args))...)
)
{
start_thread(attrs);
}
#else
template <class F,class A1>
thread(F f,A1 a1,typename disable_if<boost::is_convertible<F&,thread_attributes >, 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
);
}
}

View File

@@ -87,19 +87,13 @@ namespace boost
*/
T& get(strict_lock<mutex_type>& 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<mutex_type>& 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<Lock>& lk)
{
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<Lock>& lk) const
{
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<mutex_type> 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<mutex_type> 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<Lock> const& lk)
{
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<Lock> const& lk) const
{
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<Lock> ));
BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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<Lock> ));
BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::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()

View File

@@ -2903,7 +2903,7 @@ namespace boost
BOOST_THREAD_FUTURE<R>
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<typename boost::result_of<F()>::type>
async(BOOST_THREAD_RV_REF(F) f)
{
return async(launch::any, boost::forward<F>(f));
return async(launch(launch::any), boost::forward<F>(f));
}

View File

@@ -117,6 +117,11 @@ namespace boost
{
}
// explicit operator thread()
// {
// return boost::move(t_);
// }
/**
* Move constructor.
*/

View File

@@ -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 >*/
}

View File

@@ -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 <class Rep, class Period>
@@ -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 <typename TP>
bool try_timed_lock_until(long current_thread_id,TP const& target)
{

View File

@@ -14,7 +14,9 @@
#include <boost/thread/win32/thread_primitives.hpp>
#include <boost/thread/win32/interlocked_read.hpp>
#include <boost/thread/thread_time.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/thread/xtime.hpp>
#endif
#include <boost/detail/interlocked.hpp>
#ifdef BOOST_THREAD_USES_CHRONO
#include <boost/chrono/system_clocks.hpp>
@@ -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<typename Duration>
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 <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)

View File

@@ -11,7 +11,9 @@
#include <boost/thread/win32/thread_data.hpp>
#include <boost/thread/win32/interlocked_read.hpp>
#include <boost/thread/cv_status.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/thread/xtime.hpp>
#endif
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/thread/lock_guard.hpp>
@@ -323,6 +325,7 @@ namespace boost
}
#if defined BOOST_THREAD_USES_DATETIME
bool timed_wait(unique_lock<mutex>& 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 <class Clock, class Duration>
@@ -430,6 +433,7 @@ namespace boost
while(!pred()) wait(m);
}
#if defined BOOST_THREAD_USES_DATETIME
template<typename lock_type>
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 <class lock_type, class Clock, class Duration>

View File

@@ -12,6 +12,7 @@
#include <boost/thread/win32/basic_recursive_mutex.hpp>
#include <boost/thread/exceptions.hpp>
#include <boost/thread/detail/delete.hpp>
#if defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
#include <boost/thread/lock_types.hpp>
#endif

View File

@@ -136,12 +136,12 @@ namespace boost
BOOST_VERIFY(timed_lock_shared(::boost::detail::get_system_time_sentinel()));
}
#if defined BOOST_THREAD_USES_DATETIME
template<typename TimeDuration>
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 <class Rep, class Period>

View File

@@ -9,6 +9,7 @@
#define BOOST_XTIME_WEK070601_HPP
#include <boost/thread/detail/config.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/cstdint.hpp>
#include <boost/thread/thread_time.hpp>
@@ -88,5 +89,5 @@ inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
} // namespace boost
#include <boost/config/abi_suffix.hpp>
#endif
#endif //BOOST_XTIME_WEK070601_HPP

View File

@@ -10,12 +10,13 @@
#include <boost/thread/detail/config.hpp>
#include <boost/thread/thread.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/thread/xtime.hpp>
#endif
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/once.hpp>
#include <boost/thread/tss.hpp>
#include <boost/throw_exception.hpp>
#include <boost/thread/future.hpp>
#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
}
}

View File

@@ -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<int>(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:

View File

@@ -21,9 +21,9 @@
#include <boost/thread/future.hpp>
#include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#if defined BOOST_THREAD_USES_DATETIME
#include <boost/date_time/posix_time/conversion.hpp>
#endif
#include <memory>
#include <algorithm>
#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
}
}

View File

@@ -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 ]
;

View File

@@ -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 <boost/thread/condition_variable.hpp>
@@ -10,14 +10,14 @@
#include <boost/thread/thread_time.hpp>
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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(mutex);
if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag)
{
++woken;

View File

@@ -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<boost::mutex> 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<boost::mutex> finish_lock(finish_mutex);
{
boost::mutex::scoped_lock ublock(unblocked_count_mutex);
boost::unique_lock<boost::mutex> 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<boost::shared_mutex> lk(rwm);
{
boost::mutex::scoped_lock ulk(unblocked_mutex);
boost::unique_lock<boost::mutex> ulk(unblocked_mutex);
++unblocked_count;
}
boost::mutex::scoped_lock flk(finish_mutex);
boost::unique_lock<boost::mutex> 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<boost::shared_mutex> lk(rwm);
{
boost::mutex::scoped_lock ulk(unblocked_mutex);
boost::unique_lock<boost::mutex> ulk(unblocked_mutex);
++unblocked_count;
}
boost::mutex::scoped_lock flk(finish_mutex);
boost::unique_lock<boost::mutex> flk(finish_mutex);
}
};

View File

@@ -24,18 +24,18 @@
}
catch (boost::thread_interrupted& interrupt)
{
boost::mutex::scoped_lock lock(mutex_);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(mutex_);
cerr << "Thread " << boost::this_thread::get_id() << " caught something else" << endl;
}
}

View File

@@ -27,7 +27,7 @@ void ThreadFuncWaiter()
for (int j = 0; j < 10; j++)
{
{
boost::recursive_mutex::scoped_lock lockMtx(theMutex);
boost::unique_lock<boost::recursive_mutex> 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<boost::recursive_mutex> lockMtx(theMutex);
cout << "<Notifier " << j << endl;
unsigned int i = 0;

View File

@@ -30,7 +30,7 @@ int main()
time_t end_time;
assert(now_time < wait_time);
boost::mutex::scoped_lock lk(mtx);
boost::unique_lock<boost::mutex> lk(mtx);
//const bool res =
(void)cv.timed_wait(lk, from_time_t(wait_time));
end_time = ::time(0);

View File

@@ -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 <boost/thread.hpp>
#include <boost/config.hpp>

View File

@@ -19,7 +19,7 @@ public:
ItemKeeper() { }
void doSomething() {
boost::mutex::scoped_lock scoped_lock(mutex);
boost::unique_lock<boost::mutex> scoped_lock(mutex);
int counts = MAX_COUNTS;
while (counts--);
}

30
test/test_7665.cpp Normal file
View File

@@ -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 <iostream>
#include <boost/thread.hpp>
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;
}

View File

@@ -28,7 +28,7 @@ void barrier_thread()
{
if (gen_barrier.wait())
{
boost::mutex::scoped_lock lock(mutex);
boost::unique_lock<boost::mutex> lock(mutex);
global_parameter++;
}
}

View File

@@ -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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(data.mutex);
BOOST_CHECK(lock ? true : false);
boost::thread::sleep(delay(1));

View File

@@ -30,7 +30,7 @@ void do_test_condition_notify_all_wakes_from_wait()
}
{
boost::mutex::scoped_lock lock(data.mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lk(multiple_wake_mutex);
BOOST_CHECK(multiple_wake_count==3);
}

View File

@@ -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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lk(multiple_wake_mutex);
BOOST_CHECK(multiple_wake_count==3);
}

View File

@@ -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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(m);
boost::system_time const start=boost::get_system_time();
while(cond.timed_wait(lock,delay)) {}

View File

@@ -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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> l1(m1,boost::defer_lock),
l2(m2,boost::defer_lock),
l3(m3,boost::defer_lock),
l4(m4,boost::defer_lock),

View File

@@ -8,6 +8,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>
@@ -66,7 +67,7 @@ struct test_initially_unlocked_if_other_thread_has_lock
try
{
{
boost::mutex::scoped_lock lk(done_mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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);

View File

@@ -9,6 +9,7 @@
#include <boost/thread/detail/config.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread_time.hpp>
@@ -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<boost::mutex> 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);

View File

@@ -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<boost::mutex> lock(m);
++var_to_init;
}
@@ -39,7 +39,7 @@ void call_once_thread()
break;
}
}
boost::mutex::scoped_lock lock(m);
boost::unique_lock<boost::mutex> 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<boost::mutex> lock(m);
++(*value);
}
};
@@ -98,7 +98,7 @@ void call_once_with_functor()
break;
}
}
boost::mutex::scoped_lock lock(m);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(m);
++exception_counter;
}
}

View File

@@ -14,7 +14,7 @@
#define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \
{ \
boost::mutex::scoped_lock lock(mutex_name); \
boost::unique_lock<boost::mutex> 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<boost::mutex> finish_lock(finish_mutex);
try
{
@@ -42,7 +42,7 @@ void test_multiple_readers()
}
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
boost::unique_lock<boost::mutex> lk(unblocked_count_mutex);
while(unblocked_count<number_of_threads)
{
unblocked_condition.wait(lk);
@@ -78,7 +78,7 @@ void test_only_one_writer_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<boost::mutex> 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<boost::mutex> finish_lock(finish_mutex);
try
{
@@ -126,7 +126,7 @@ void test_reader_blocks_writer()
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lk(unblocked_count_mutex);
while(unblocked_count<reader_count)
{
unblocked_condition.wait(lk);
@@ -217,9 +217,9 @@ void test_unlocking_last_reader_only_unblocks_one_writer()
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_reading_mutex;
boost::mutex::scoped_lock finish_reading_lock(finish_reading_mutex);
boost::unique_lock<boost::mutex> finish_reading_lock(finish_reading_mutex);
boost::mutex finish_writing_mutex;
boost::mutex::scoped_lock finish_writing_lock(finish_writing_mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> lk(unblocked_count_mutex);
while(unblocked_count<reader_count)
{
unblocked_condition.wait(lk);
@@ -250,7 +250,7 @@ void test_unlocking_last_reader_only_unblocks_one_writer()
finish_reading_lock.unlock();
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
boost::unique_lock<boost::mutex> lk(unblocked_count_mutex);
while(unblocked_count<(reader_count+1))
{
unblocked_condition.wait(lk);

View File

@@ -13,7 +13,7 @@
#define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \
{ \
boost::mutex::scoped_lock lock(mutex_name); \
boost::unique_lock<boost::mutex> lock(mutex_name); \
BOOST_CHECK_EQUAL(value,expected_value); \
}
@@ -40,11 +40,11 @@ public:
boost::upgrade_lock<boost::shared_mutex> lk(rwm);
{
boost::mutex::scoped_lock ulk(unblocked_mutex);
boost::unique_lock<boost::mutex> ulk(unblocked_mutex);
++unblocked_count;
}
boost::mutex::scoped_lock flk(finish_mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::upgrade_lock<boost::shared_mutex> >(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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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);

View File

@@ -13,7 +13,7 @@
#define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \
{ \
boost::mutex::scoped_lock lock(mutex_name); \
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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);

View File

@@ -15,7 +15,7 @@
#define CHECK_LOCKED_VALUE_EQUAL(mutex_name,value,expected_value) \
{ \
boost::mutex::scoped_lock lock(mutex_name); \
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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);

View File

@@ -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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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<boost::mutex> lk(f.mut);
f.done=true;
f.cond.notify_one();
}

View File

@@ -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 <boost/thread/thread.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/ref.hpp>

View File

@@ -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 <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -34,14 +34,14 @@ struct tss_value_t
{
tss_value_t()
{
boost::mutex::scoped_lock lock(tss_mutex);
boost::unique_lock<boost::mutex> lock(tss_mutex);
++tss_instances;
++tss_total;
value = 0;
}
~tss_value_t()
{
boost::mutex::scoped_lock lock(tss_mutex);
boost::unique_lock<boost::mutex> 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<boost::mutex> lock(check_mutex);
BOOST_CHECK_EQUAL(n, i);
}
++n;

View File

@@ -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<boost::mutex> 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)));

View File

@@ -33,7 +33,7 @@ void join_all(TC & tc)
void increment_count()
{
boost::mutex::scoped_lock lock(mutex);
boost::unique_lock<boost::mutex> lock(mutex);
std::cout << "count = " << ++count << std::endl;
}

View File

@@ -40,7 +40,7 @@ void interrupt_all(TC & tc)
void increment_count()
{
boost::mutex::scoped_lock lock(mutex);
boost::unique_lock<boost::mutex> lock(mutex);
std::cout << "count = " << ++count << std::endl;
}

View File

@@ -74,7 +74,7 @@ public:
void start()
{
if (type != use_sleep_only) {
boost::mutex::scoped_lock lock(mutex); done = false;
boost::unique_lock<boost::mutex> 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<boost::mutex> 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<boost::mutex> lock(mutex);
while (type == use_condition && !done) {
if (!cond.timed_wait(lock, xt))
break;