2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-21 03:22:10 +00:00

Thread: merge from trunk 1.53

[SVN r81667]
This commit is contained in:
Vicente J. Botet Escriba
2012-12-02 09:22:33 +00:00
parent 0ae81b8d4c
commit ad3247dd29
287 changed files with 14828 additions and 3477 deletions

View File

@@ -23,6 +23,8 @@ project
: requirements
<threading>multi
<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
<warnings>all
<toolset>gcc:<cxxflags>-Wextra
<toolset>gcc:<cxxflags>-pedantic
@@ -43,7 +45,7 @@ project
<toolset>clang:<cxxflags>-Wextra
<toolset>clang:<cxxflags>-pedantic
<toolset>clang:<cxxflags>-Wno-long-long
<toolset>clang:<cxxflags>-ansi
#<toolset>clang:<cxxflags>-ansi
#<toolset>clang:<cxxflags>-fpermissive # doesn't work
<toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
@@ -66,6 +68,19 @@ project
#<toolset>clang-3.0:<cxxflags>-Wno-unused-function
#<toolset>clang-3.0:<cxxflags>-Wno-unused-variable
# Note: Some of the remarks from the Intel compiler are disabled
# remark #193: zero used for undefined preprocessing identifier "XXX"
# remark #304: access control not specified ("public" by default)
# remark #593: variable "XXX" was set but never used
# remark #1418: external function definition with no prior declaration
# remark #2415: variable "XXX" of static storage duration was declared but never referenced
<toolset>intel:<cxxflags>-wd193,304,383,444
<toolset>intel:<cxxflags>-wd593,981
<toolset>intel:<cxxflags>-wd1418
<toolset>intel:<cxxflags>-wd2415
;
rule thread-run ( sources )
@@ -77,6 +92,7 @@ rule thread-run ( sources )
;
}
rule thread-test ( sources )
{
return
@@ -102,6 +118,18 @@ rule thread-run2 ( sources : name )
;
}
rule thread-run2-h ( sources : name )
{
return
[ run $(sources) : : :
<library>/boost/system//boost_system
<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
<define>BOOST_THREAD_VERSION=3
: $(name)_h ]
;
}
rule thread-run-lib2 ( sources : name )
{
return
@@ -187,10 +215,11 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run test_5542_3.cpp ]
[ thread-run test_5891.cpp ]
[ thread-run test_6130.cpp ]
[ thread-run test_6170.cpp ]
#[ thread-run test_6170.cpp ]
[ thread-run test_6174.cpp ]
[ thread-run test_7160.cpp ]
#[ thread-run test_7160.cpp ]
[ thread-run test_7328.cpp ]
[ thread-run test_7571.cpp ]
;
@@ -228,7 +257,7 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/conditions/notify_all_at_thread_exit_pass.cpp : notify_all_at_thread_exit_p ]
;
explicit ts_async ;
#explicit ts_async ;
test-suite ts_async
:
[ thread-run2 ./sync/futures/async/async_pass.cpp : async__async_p ]
@@ -245,7 +274,17 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/futures/promise/get_future_pass.cpp : promise__get_future_p ]
[ thread-run2 ./sync/futures/promise/move_ctor_pass.cpp : promise__move_ctor_p ]
[ thread-run2 ./sync/futures/promise/move_assign_pass.cpp : promise__move_asign_p ]
[ thread-run2 ./sync/futures/promise/set_exception_pass.cpp : promise__set_exception_p ]
[ thread-run2 ./sync/futures/promise/set_lvalue_pass.cpp : promise__set_lvalue_p ]
[ thread-run2 ./sync/futures/promise/set_rvalue_pass.cpp : promise__set_rvalue_p ]
[ thread-run2 ./sync/futures/promise/set_value_const_pass.cpp : promise__set_value_const_p ]
[ thread-run2 ./sync/futures/promise/set_value_void_pass.cpp : promise__set_value_void_p ]
[ thread-run2 ./sync/futures/promise/use_allocator_pass.cpp : promise__use_allocator_p ]
[ thread-run2 ./sync/futures/promise/set_exception_at_thread_exit_pass.cpp : promise__set_exception_at_thread_exit_p ]
[ thread-run2 ./sync/futures/promise/set_lvalue_at_thread_exit_pass.cpp : promise__set_lvalue_at_thread_exit_p ]
[ thread-run2 ./sync/futures/promise/set_rvalue_at_thread_exit_pass.cpp : promise__set_rvalue_at_thread_exit_p ]
[ thread-run2 ./sync/futures/promise/set_value_at_thread_exit_const_pass.cpp : promise__set_value_at_thread_exit_const_p ]
[ thread-run2 ./sync/futures/promise/set_value_at_thread_exit_void_pass.cpp : promise__set_value_at_thread_exit_void_p ]
;
#explicit ts_future ;
@@ -255,10 +294,23 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-compile-fail ./sync/futures/future/copy_ctor_fail.cpp : : future__copy_ctor_f ]
[ thread-run2 ./sync/futures/future/default_pass.cpp : future__default_p ]
[ thread-run2 ./sync/futures/future/dtor_pass.cpp : future__dtor_p ]
#[ thread-run2 ./sync/futures/future/get_pass.cpp : future__get_p ]
[ thread-run2 ./sync/futures/future/get_pass.cpp : future__get_p ]
[ thread-run2 ./sync/futures/future/move_ctor_pass.cpp : future__move_ctor_p ]
[ thread-run2 ./sync/futures/future/move_assign_pass.cpp : future__move_asign_p ]
[ thread-run2 ./sync/futures/future/share_pass.cpp : future__share_p ]
[ thread-run2 ./sync/futures/future/then_pass.cpp : future__then_p ]
;
#explicit ts_shared_future ;
test-suite ts_shared_future
:
[ thread-run2 ./sync/futures/shared_future/copy_assign_pass.cpp : shared_future__copy_assign_p ]
[ thread-run2 ./sync/futures/shared_future/copy_ctor_pass.cpp : shared_future__copy_ctor_p ]
[ thread-run2 ./sync/futures/shared_future/default_pass.cpp : shared_future__default_p ]
[ thread-run2 ./sync/futures/shared_future/dtor_pass.cpp : shared_future__dtor_p ]
[ thread-run2 ./sync/futures/shared_future/get_pass.cpp : shared_future__get_p ]
[ thread-run2 ./sync/futures/shared_future/move_ctor_pass.cpp : shared_future__move_ctor_p ]
[ thread-run2 ./sync/futures/shared_future/move_assign_pass.cpp : shared_future__move_asign_p ]
;
#explicit ts_packaged_task ;
@@ -269,16 +321,17 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-compile-fail ./sync/futures/packaged_task/copy_ctor_fail.cpp : : packaged_task__copy_ctor_f ]
[ thread-run2 ./sync/futures/packaged_task/default_ctor_pass.cpp : packaged_task__default_ctor_p ]
[ thread-run2 ./sync/futures/packaged_task/func_ctor_pass.cpp : packaged_task__func_ctor_p ]
#[ thread-run2 ./sync/futures/packaged_task/dtor_pass.cpp : packaged_task__dtor_p ]
[ thread-run2 ./sync/futures/packaged_task/dtor_pass.cpp : packaged_task__dtor_p ]
[ thread-run2 ./sync/futures/packaged_task/get_future_pass.cpp : packaged_task__get_future_p ]
[ thread-run2 ./sync/futures/packaged_task/move_ctor_pass.cpp : packaged_task__move_ctor_p ]
[ thread-run2 ./sync/futures/packaged_task/move_assign_pass.cpp : packaged_task__move_asign_p ]
#[ thread-run2 ./sync/futures/packaged_task/operator_pass.cpp : packaged_task__operator_p ]
[ thread-run2 ./sync/futures/packaged_task/operator_pass.cpp : packaged_task__operator_p ]
[ thread-run2 ./sync/futures/packaged_task/reset_pass.cpp : packaged_task__reset_p ]
[ thread-run2 ./sync/futures/packaged_task/use_allocator_pass.cpp : packaged_task__use_allocator_p ]
[ thread-run2 ./sync/futures/packaged_task/types_pass.cpp : packaged_task__types_p ]
[ thread-run2 ./sync/futures/packaged_task/member_swap_pass.cpp : packaged_task__member_swap_p ]
[ thread-run2 ./sync/futures/packaged_task/non_member_swap_pass.cpp : packaged_task__non_member_swap_p ]
[ thread-run2 ./sync/futures/packaged_task/make_ready_at_thread_exit_pass.cpp : packaged_task__make_ready_at_thread_exit_p ]
;
@@ -290,6 +343,8 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp : lock_guard__cons__adopt_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/default_pass.cpp : lock_guard__cons__default_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/types_pass.cpp : lock_guard__types_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/make_lock_guard_pass.cpp : make_lock_guard_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/make_lock_guard_adopt_lock_pass.cpp : make_lock_guard__adopt_lock_p ]
;
#explicit ts_unique_lock ;
@@ -320,9 +375,23 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp : unique_lock__release_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp : unique_lock__mutex_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp : unique_lock__op_bool_p ]
[ thread-compile-fail ./sync/mutual_exclusion/locks/unique_lock/obs/op_int_fail.cpp : : unique_lock__op_int_f ]
#[ thread-compile-fail ./sync/mutual_exclusion/locks/unique_lock/obs/op_int_fail.cpp : : unique_lock__op_int_f ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp : unique_lock__owns_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/types_pass.cpp : unique_lock__types_p ]
;
#explicit ts_make_unique_lock ;
test-suite ts_make_unique_lock
:
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_mutex_pass.cpp : make_unique_lock__mutex_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_adopt_lock_pass.cpp : make_unique_lock__adopt_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp : make_unique_lock__defer_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_try_to_lock_pass.cpp : make_unique_lock__try_to_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/make_unique_locks_mutex_pass.cpp : make_unique_locks__mutex_p ]
;
#explicit ts_shared_lock ;
@@ -353,6 +422,10 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp : shared_lock__op_bool_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp : shared_lock__owns_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/types_pass.cpp : shared_lock__types_p ]
[ thread-run2-h ./sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp : shared_lock__cons__default_p ]
[ thread-run2-h ./sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp : shared_lock__cons__defer_lock_p ]
;
#explicit ts_upgrade_lock ;
@@ -443,6 +516,7 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/try_lock_pass.cpp : shared_mutex__try_lock_p ]
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/try_lock_until_pass.cpp : shared_mutex__try_lock_until_p ]
[ thread-run2-h ./sync/mutual_exclusion/shared_mutex/default_pass.cpp : shared_mutex__default_p ]
;
#explicit ts_this_thread ;
@@ -463,7 +537,7 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run-lib2 ./threads/thread/constr/F_pass.cpp : thread__constr__F_p ]
[ thread-run-lib2 ./threads/thread/constr/FArgs_pass.cpp : thread__constr__FArgs_p ]
[ thread-run2 ./threads/thread/constr/Frvalue_pass.cpp : thread__constr__Frvalue_p ]
#[ thread-run2 ./threads/thread/constr/FrvalueArgs_pass.cpp : thread__constr__FrvalueArgs_p ]
[ thread-run2 ./threads/thread/constr/FrvalueArgs_pass.cpp : thread__constr__FrvalueArgs_p ]
[ thread-run2 ./threads/thread/constr/move_pass.cpp : thread__constr__move_p ]
[ thread-run2 ./threads/thread/destr/dtor_pass.cpp : thread__destr__dtor_p ]
[ thread-run2 ./threads/thread/id/hash_pass.cpp : thread__id__hash_p ]
@@ -504,6 +578,15 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run ../example/shared_mutex.cpp ]
#[ thread-run ../example/vhh_shared_monitor.cpp ]
#[ thread-run ../example/vhh_shared_mutex.cpp ]
[ thread-run ../example/make_future.cpp ]
[ thread-run ../example/future_then.cpp ]
[ thread-run ../example/synchronized_value.cpp ]
[ thread-run ../example/synchronized_person.cpp ]
[ thread-run ../example/thread_guard.cpp ]
[ thread-run ../example/scoped_thread.cpp ]
[ thread-run ../example/strict_lock.cpp ]
[ thread-run ../example/ba_externallly_locked.cpp ]
;
#explicit ts_shared_upwards ;
@@ -538,4 +621,12 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp : reverse_lock__types_p ]
;
explicit ts_ ;
test-suite ts_
:
#[ thread-run test_7665.cpp ]
#[ thread-run test_7666.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

@@ -22,10 +22,12 @@
// future<typename result_of<F(Args...)>::type>
// async(launch policy, F&& f, Args&&... args);
#define BOOST_THREAD_VERSION 3
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/detail/memory.hpp>
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#include <memory>
#include <boost/detail/lightweight_test.hpp>
@@ -38,7 +40,7 @@ class A
long data_;
public:
typedef int result_type;
typedef long result_type;
explicit A(long i) : data_(i) {}
@@ -93,149 +95,293 @@ boost::interprocess::unique_ptr<int, boost::default_delete<int> > f3(int i)
return boost::interprocess::unique_ptr<int, boost::default_delete<int> >(new int(i));
}
typedef boost::interprocess::unique_ptr<int, boost::default_delete<int> > XXT;
boost::interprocess::unique_ptr<int, boost::default_delete<int> > f4(
BOOST_THREAD_RV_REF(boost::interprocess::unique_ptr<int, boost::default_delete<int> > ) p)
BOOST_THREAD_RV_REF_BEG boost::interprocess::unique_ptr<int, boost::default_delete<int> > BOOST_THREAD_RV_REF_END p
)
{
boost::this_thread::sleep_for(ms(200));
return boost::move(p);
}
int main()
{
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int> f = boost::async(f0);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int> f = boost::async(boost::launch::async, f0);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
boost::future<int> f = boost::async(boost::launch::async, A(3));
try {
boost::future<long> f = boost::async(boost::launch::async, A(3));
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int> f = boost::async(boost::launch::async, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int> f = boost::async(boost::launch::any, f0);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
// {
// boost::future<int> f = boost::async(boost::launch::deferred, f0);
// boost::this_thread::sleep_for(ms(300));
// Clock::time_point t0 = Clock::now();
// BOOST_TEST(f.get() == 3);
// Clock::time_point t1 = Clock::now();
// BOOST_TEST(t1 - t0 > ms(100));
// }
//
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int> f = boost::async(boost::launch::deferred, f0);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 > ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
#endif
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int&> f = boost::async(f1);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(&f.get() == &i);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int&> f = boost::async(boost::launch::async, f1);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(&f.get() == &i);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<int&> f = boost::async(boost::launch::any, f1);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(&f.get() == &i);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
// {
// boost::future<int&> f = boost::async(boost::launch::deferred, f1);
// boost::this_thread::sleep_for(ms(300));
// Clock::time_point t0 = Clock::now();
// BOOST_TEST(&f.get() == &i);
// Clock::time_point t1 = Clock::now();
// BOOST_TEST(t1 - t0 > ms(100));
// }
//
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
boost::future<void> f = boost::async(f2);
try {
boost::future<int&> f = boost::async(boost::launch::deferred, f1);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
f.get();
BOOST_TEST(&f.get() == &i);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
BOOST_TEST(t1 - t0 > ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
#endif
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<void> f = boost::async(f2);
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
boost::this_thread::sleep_for(ms(300));
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
Clock::time_point t0 = Clock::now();
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
f.get();
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
Clock::time_point t1 = Clock::now();
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<void> f = boost::async(boost::launch::async, f2);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
f.get();
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<void> f = boost::async(boost::launch::any, f2);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
f.get();
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
// {
// boost::future<void> f = boost::async(boost::launch::deferred, f2);
// boost::this_thread::sleep_for(ms(300));
// Clock::time_point t0 = Clock::now();
// f.get();
// Clock::time_point t1 = Clock::now();
// BOOST_TEST(t1 - t0 > ms(100));
// }
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<void> f = boost::async(boost::launch::deferred, f2);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
f.get();
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 > ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
#endif
// {
// boost::future<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > f = boost::async(f3, 3);
// boost::this_thread::sleep_for(ms(300));
// Clock::time_point t0 = Clock::now();
// BOOST_TEST(*f.get() == 3);
// Clock::time_point t1 = Clock::now();
// BOOST_TEST(t1 - t0 < ms(100));
// }
// todo fixme
#if 0 && defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try {
boost::future<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > f = boost::async(boost::launch::async, &f3, 3);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(*f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
#endif
// {
// boost::future<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > f = boost::async(f4, boost::interprocess::unique_ptr<int, boost::default_delete<int> >(new int(3)));
// boost::this_thread::sleep_for(ms(300));
// Clock::time_point t0 = Clock::now();
// BOOST_TEST(*f.get() == 3);
// Clock::time_point t1 = Clock::now();
// BOOST_TEST(t1 - t0 < ms(100));
// }
// todo fixme
#if 0 && defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
{
try {
boost::future<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > f = boost::async(&f4, boost::interprocess::unique_ptr<int, boost::default_delete<int> >(new int(3)));
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
BOOST_TEST(*f.get() == 3);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 < ms(100));
} catch (std::exception& ex) {
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
} catch (...) {
BOOST_TEST(false && "exception thrown");
}
}
#endif
return boost::report_errors();
}

View File

@@ -14,9 +14,9 @@
// <boost/thread/future.hpp>
// class promise<R>
// class future<R>
// ~promise();
// ~future();
#define BOOST_THREAD_VERSION 3
#include <boost/exception/exception.hpp>

View File

@@ -14,16 +14,21 @@
// <boost/thread/future.hpp>
// class promise<R>
// class future<R>
// future<R> get_future();
// const R& future::get();
// R& future<R&>::get();
// void future<void>::get();
#define BOOST_THREAD_VERSION 3
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
namespace boost
{
template <typename T>
@@ -76,7 +81,7 @@ void func5(boost::promise<void> p)
void func6(boost::promise<void> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_exception(boost::make_exception_ptr('c'));
p.set_exception(boost::make_exception_ptr(4));
}
@@ -87,85 +92,130 @@ int main()
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
boost::thread(func1, boost::move(p)).detach();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func1, boost::move(p)).detach();
#else
p.set_value(3);
#endif
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func2, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(3));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (int i)
catch (boost::wrap<int> const& i)
{
BOOST_TEST(i == 3);
BOOST_TEST(i.value == 3);
}
catch (...)
{
BOOST_TEST(false);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
}
{
typedef int& T;
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func3, boost::move(p)).detach();
#else
int j=5;
p.set_value(j);
#endif
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 5);
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func4, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (boost::wrap<double> const& i)
{
BOOST_TEST(i.value == 3.5);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
}
// {
// typedef int& T;
// {
// boost::promise<T> p;
// boost::future<T> f = p.get_future();
// boost::thread(func3, boost::move(p)).detach();
// BOOST_TEST(f.valid());
// BOOST_TEST(f.get() == 5);
// BOOST_TEST(!f.valid());
// }
// {
// boost::promise<T> p;
// boost::future<T> f = p.get_future();
// boost::thread(func4, boost::move(p)).detach();
// try
// {
// BOOST_TEST(f.valid());
// BOOST_TEST(f.get() == 3);
// BOOST_TEST(false);
// }
// catch (double i)
// {
// BOOST_TEST(i == 3.5);
// }
// BOOST_TEST(!f.valid());
// }
// }
// {
// typedef void T;
// {
// boost::promise<T> p;
// boost::future<T> f = p.get_future();
// boost::thread(func5, boost::move(p)).detach();
// BOOST_TEST(f.valid());
// f.get();
// BOOST_TEST(!f.valid());
// }
// {
// boost::promise<T> p;
// boost::future<T> f = p.get_future();
// boost::thread(func6, boost::move(p)).detach();
// try
// {
// BOOST_TEST(f.valid());
// f.get();
// BOOST_TEST(false);
// }
// catch (char i)
// {
// BOOST_TEST(i == 'c');
// }
// BOOST_TEST(!f.valid());
// }
// }
typedef void T;
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func5, boost::move(p)).detach();
#else
p.set_value();
#endif
BOOST_TEST(f.valid());
f.get();
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
{
boost::promise<T> p;
boost::future<T> f = p.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func6, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(4));
#endif
try
{
BOOST_TEST(f.valid());
f.get();
BOOST_TEST(false);
}
catch (boost::wrap<int> const& i)
{
BOOST_TEST(i.value == 4);
}
catch (...)
{
BOOST_TEST(false);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
return boost::report_errors();
}
#else
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif

View File

@@ -14,9 +14,9 @@
// <future>
// class promise<R>
// class future<R>
// promise& operator=(promise&& rhs);
// future& operator=(future&& rhs);
#define BOOST_THREAD_VERSION 3

View File

@@ -14,9 +14,9 @@
// <future>
// class promise<R>
// class future<R>
// promise(promise&& rhs);
// future(future&& rhs);
#define BOOST_THREAD_VERSION 3

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class future<R>
// template<typename F>
// auto then(F&& func) -> BOOST_THREAD_FUTURE<decltype(func(*this))>;
#define BOOST_THREAD_VERSION 4
#define BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
int p1()
{
return 1;
}
int p2(boost::future<int>& f)
{
return 2 * f.get();
}
int main()
{
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f2 = f1.then(p2);
BOOST_TEST(f2.get()==2);
}
{
boost::future<int> f2 = boost::async(p1).then(p2);
BOOST_TEST(f2.get()==2);
}
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f2 = f1.then(p2).then(p2);
BOOST_TEST(f2.get()==4);
}
{
boost::future<int> f2 = boost::async(p1).then(p2).then(p2);
BOOST_TEST(f2.get()==4);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -20,10 +20,18 @@
// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/detail/config.hpp>
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
@@ -81,7 +89,7 @@ int A::n_destroy = 0;
int main()
{
{
boost::packaged_task<double> p(boost::allocator_arg,
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), BOOST_THREAD_MAKE_RV_REF(A(5)));
BOOST_TEST(test_alloc_base::count > 0);
BOOST_TEST(p.valid());
@@ -96,10 +104,10 @@ int main()
BOOST_TEST(A::n_destroy > 0);
BOOST_TEST(test_alloc_base::count == 0);
A::n_copies = 0;
A::n_copies = 0;
A::n_moves = 0;
{
A a(5);
boost::packaged_task<double> p(boost::allocator_arg,
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), a);
BOOST_TEST(test_alloc_base::count > 0);
BOOST_TEST(p.valid());
@@ -108,14 +116,14 @@ int main()
p();
BOOST_TEST(f.get() == 5.0);
}
BOOST_TEST(A::n_copies > 0);
BOOST_TEST(A::n_moves > 0);
//BOOST_TEST(A::n_copies > 0);
//BOOST_TEST(A::n_moves > 0);
BOOST_TEST(test_alloc_base::count == 0);
A::n_copies = 0;
A::n_copies = 0;
A::n_moves = 0;
{
const A a(5);
boost::packaged_task<double> p(boost::allocator_arg,
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), a);
BOOST_TEST(test_alloc_base::count > 0);
BOOST_TEST(p.valid());
@@ -124,11 +132,11 @@ int main()
p();
BOOST_TEST(f.get() == 5.0);
}
BOOST_TEST(A::n_copies > 0);
BOOST_TEST(A::n_moves > 0);
//BOOST_TEST(A::n_copies > 0);
//BOOST_TEST(A::n_moves > 0);
BOOST_TEST(test_alloc_base::count == 0);
{
boost::packaged_task<double> p(boost::allocator_arg,
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), fct);
BOOST_TEST(test_alloc_base::count > 0);
BOOST_TEST(p.valid());
@@ -138,7 +146,7 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p(boost::allocator_arg,
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), &lfct);
BOOST_TEST(test_alloc_base::count > 0);
BOOST_TEST(p.valid());

View File

@@ -18,7 +18,13 @@
// packaged_task& operator=(packaged_task&) = delete;
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -37,8 +43,8 @@ public:
int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p = p0;
}

View File

@@ -18,7 +18,13 @@
// packaged_task(packaged_task&) = delete;
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -37,8 +43,8 @@ public:
int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p(p0);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(p0);
}

View File

@@ -18,7 +18,13 @@
// packaged_task();
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE int()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE int
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -26,7 +32,7 @@
int main()
{
{
boost::packaged_task<int> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
BOOST_TEST(!p.valid());
}

View File

@@ -17,14 +17,34 @@
// class packaged_task<R>
// ~packaged_task();
;
#define BOOST_THREAD_VERSION 3
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double(int, char)
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5 + 3 +'a'
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
class A
{
long data_;
@@ -36,25 +56,33 @@ public:
long operator()(long i, long j) const {return data_ + i + j;}
};
void func(boost::packaged_task<double> p)
void func(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> )
{
}
void func2(boost::packaged_task<double> p)
void func2(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
//p(3, 'a');
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
}
int main()
{
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func, boost::move(p)).detach();
#else
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>* p2=new boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>(boost::move(p));
delete p2;
#endif
try
{
double i = f.get();
f.get();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
@@ -63,13 +91,18 @@ int main()
}
}
{
boost::packaged_task<double> p(A(5));
std::cout << __LINE__ << std::endl;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func2, boost::move(p)).detach();
BOOST_TEST(f.get() == 5.0);
#else
p();
#endif
std::cout << __LINE__ << std::endl;
BOOST_TEST(f.get() == BOOST_THREAD_DETAIL_SIGNATURE_2_RES);
std::cout << __LINE__ << std::endl;
}
return boost::report_errors();
}

View File

@@ -19,10 +19,30 @@
// explicit packaged_task(F&& f);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double(int, char)
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5 + 3 +'a'
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
double fct()
{
return 5.0;
@@ -69,44 +89,47 @@ int A::n_copies = 0;
int main()
{
{
boost::packaged_task<double> p(BOOST_THREAD_MAKE_RV_REF(A(5)));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(A(5)));
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
BOOST_TEST(f.get() == 5.0);
#endif
BOOST_TEST(f.get() == BOOST_THREAD_DETAIL_SIGNATURE_2_RES);
BOOST_TEST(A::n_copies == 0);
BOOST_TEST(A::n_moves > 0);
}
A::n_copies = 0;
A::n_copies = 0;
A::n_moves = 0;
{
A a(5);
boost::packaged_task<double> p(a);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(a);
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
p();
BOOST_TEST(f.get() == 5.0);
BOOST_TEST(A::n_copies > 0);
BOOST_TEST(A::n_moves > 0);
//BOOST_TEST(A::n_copies > 0);
//BOOST_TEST(A::n_moves > 0);
}
A::n_copies = 0;
A::n_copies = 0;
A::n_moves = 0;
{
const A a(5);
boost::packaged_task<double> p(a);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(a);
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
p();
BOOST_TEST(f.get() == 5.0);
BOOST_TEST(A::n_copies > 0);
BOOST_TEST(A::n_moves > 0);
//BOOST_TEST(A::n_copies > 0);
//BOOST_TEST(A::n_moves > 0);
}
{
boost::packaged_task<double> p(fct);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(fct);
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
@@ -114,7 +137,7 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p(&lfct);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(&lfct);
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');

View File

@@ -19,7 +19,12 @@
// future<R> get_future();
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -38,14 +43,14 @@ public:
int main()
{
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
p();
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
try
{
@@ -58,7 +63,7 @@ int main()
}
}
{
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
try
{
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());

View File

@@ -0,0 +1,146 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class packaged_task<R>
// packaged_task(packaged_task&& other);
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO && \
defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && \
defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
class E : public std::exception
{
public:
long data;
explicit E(long i) :
data(i)
{
}
const char* what() const throw() { return ""; }
~E() throw() {}
};
class A
{
long data_;
public:
explicit A(long i) :
data_(i)
{
}
long operator()(long i, long j) const
{
if (j == 'z') BOOST_THROW_EXCEPTION( E(6) );
return data_ + i + j;
}
};
void func0(boost::packaged_task<double(int, char)> *p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p->make_ready_at_thread_exit(3, 'a');
}
void func1(boost::packaged_task<double(int, char)> *p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p->make_ready_at_thread_exit(3, 'z');
}
void func2(boost::packaged_task<double(int, char)> *p)
{
p->make_ready_at_thread_exit(3, 'a');
try
{
p->make_ready_at_thread_exit(3, 'c');
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
}
void func3(boost::packaged_task<double(int, char)> *p)
{
try
{
p->make_ready_at_thread_exit(3, 'a');
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
int main()
{
{
boost::packaged_task<double(int, char)> p(A(5));
boost::future<double> f = p.get_future();
// BUG boost::thread(func0, boost::move(p)).detach();
boost::thread(func0, &p).detach();
BOOST_TEST(f.get() == 105.0);
}
{
boost::packaged_task<double(int, char)> p(A(5));
boost::future<double> f = p.get_future();
//boost::thread(func1, boost::move(p)).detach();
boost::thread(func1, &p).detach();
try
{
f.get();
BOOST_TEST(false);
}
catch (const E& e)
{
BOOST_TEST(e.data == 6);
}
}
{
boost::packaged_task<double(int, char)> p(A(5));
boost::future<double> f = p.get_future();
//boost::thread(func2, boost::move(p)).detach();
boost::thread(func2, &p).detach();
BOOST_TEST(f.get() == 105.0);
}
{
boost::packaged_task<double(int, char)> p;
//boost::thread t(func3, boost::move(p));
boost::thread t(func3, &p);
t.join();
}
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
//#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif

View File

@@ -18,7 +18,12 @@
// void swap(packaged_task& other);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -46,8 +51,8 @@ public:
int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(p.valid());
@@ -57,8 +62,8 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p0;
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());

View File

@@ -18,7 +18,12 @@
// promise& operator=(promise&& rhs);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -39,8 +44,8 @@ int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p = boost::move(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(p.valid());
@@ -50,8 +55,8 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p0;
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p = boost::move(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());

View File

@@ -18,7 +18,12 @@
// packaged_task(packaged_task&& other);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -38,8 +43,8 @@ public:
int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p = boost::move(p0);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p = boost::move(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
@@ -48,8 +53,8 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p0;
boost::packaged_task<double> p = boost::move(p0);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p = boost::move(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());
}

View File

@@ -18,7 +18,12 @@
// void
// swap(packaged_task<R>& x, packaged_task<R>& y);
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -37,8 +42,8 @@ public:
int main()
{
{
boost::packaged_task<double> p0(A(5));
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(p.valid());
@@ -48,8 +53,8 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p0;
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());

View File

@@ -18,10 +18,46 @@
// void operator()();
#define BOOST_THREAD_VERSION 3
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double(int, char)
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5 + 3 +'a'
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#endif
class E : public std::exception
{
public:
long data;
explicit E(long i) :
data(i)
{
}
const char* what() const throw() { return ""; }
~E() throw() {}
};
class A
{
long data_;
@@ -34,93 +70,149 @@ public:
long operator()() const
{
if (data_ == 0) BOOST_THROW_EXCEPTION(E(6));
return data_;
}
long operator()(long i, long j) const
{
if (j == 'z') throw A(6);
if (j == 'z') BOOST_THROW_EXCEPTION(E(6));
return data_ + i + j;
}
~A() {}
};
void func0(boost::packaged_task<double> p)
void func0(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
//p(3, 'a');
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
}
void func1(boost::packaged_task<double(int, char)> p)
void func1(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
//p(3, 'z');
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'z');
#else
p();
#endif
}
void func2(boost::packaged_task<double(int, char)> p)
void func2(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
//p(3, 'a');
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
try
{
//p(3, 'c');
p();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'c');
#else
p();
#endif
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == make_error_code(boost::future_errc::promise_already_satisfied));
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
}
void func3(boost::packaged_task<double(int, char)> p)
void func3(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
try
{
//p(3, 'a');
p();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == make_error_code(boost::future_errc::no_state));
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
int main()
{
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func0, boost::move(p)).detach();
BOOST_TEST(f.get() == 5.0);
#else
//p();
#endif
//BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(A(0));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func1, boost::move(p)).detach();
#endif
try
{
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
p();
#endif
f.get();
BOOST_TEST(false);
}
catch (const A& e)
catch (const E& e)
{
//BOOST_TEST(e(3, 'a') == 106);
BOOST_TEST(e() == 5);
BOOST_TEST(e.data == 6);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread t(func2, boost::move(p));
BOOST_TEST(f.get() == 5.0);
#else
p();
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
BOOST_TEST(f.get() == 105);
t.join();
#else
BOOST_TEST(f.get() == 5.0);
#endif
}
{
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p;
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread t(func3, boost::move(p));
t.join();
#else
try
{
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
#endif
}
return boost::report_errors();
}
#else
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif

View File

@@ -18,7 +18,13 @@
// void operator()();
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -46,7 +52,7 @@ public:
int main()
{
{
boost::packaged_task<double> p(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
//p(3, 'a');
p();
@@ -58,7 +64,7 @@ int main()
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<double> p;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
try
{
p.reset();

View File

@@ -29,7 +29,7 @@ struct A {};
int main()
{
BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::packaged_task<A>::result_type, A>::value), "");
//BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::packaged_task<A>::result_type, A>::value), "");
return boost::report_errors();
}

View File

@@ -21,7 +21,12 @@
// : true_type { };
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#endif
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -33,7 +38,7 @@
int main()
{
BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::packaged_task<double>, test_allocator<double> >::value), "");
BOOST_STATIC_ASSERT_MSG((boost::uses_allocator<boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>, test_allocator<double> >::value), "");
return boost::report_errors();
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_exception_at_thread_exit(exception_ptr p);
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
namespace boost
{
template <typename T>
struct wrap
{
wrap(T const& v) :
value(v)
{
}
T value;
};
template <typename T>
exception_ptr make_exception_ptr(T v)
{
return copy_exception(wrap<T> (v));
}
}
//void func(boost::promise<int> p)
boost::promise<int> p;
void func()
{
p.set_exception_at_thread_exit(boost::make_exception_ptr(3));
}
int main()
{
{
typedef int T;
//boost::promise<T> p;
boost::future<T> f = p.get_future();
//boost::thread(func, boost::move(p)).detach();
boost::thread(func).detach();
try
{
f.get();
BOOST_TEST(false);
}
catch (boost::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void set_exception(exception_ptr p);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
namespace boost
{
template <typename T>
struct wrap
{
wrap(T const& v) :
value(v)
{
}
T value;
};
template <typename T>
exception_ptr make_exception_ptr(T v)
{
return copy_exception(wrap<T> (v));
}
}
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_exception(boost::make_exception_ptr(3));
try
{
f.get();
BOOST_TEST(false);
}
catch (boost::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
try
{
p.set_exception(boost::make_exception_ptr(3));
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise<R&>::set_value_at_thread_exit(R& r);
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>
int i = 0;
//void func(boost::promise<int&> p)
boost::promise<int&> p;
void func()
{
p.set_value_at_thread_exit(i);
i = 4;
}
int main()
{
{
//boost::promise<int&> p;
boost::future<int&> f = p.get_future();
//boost::thread(func, boost::move(p)).detach();
boost::thread(func).detach();
int r = f.get();
BOOST_TEST(r == 4);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise<R&>::set_value(R& r);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
int main()
{
{
typedef int& T;
int i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(i);
int& j = f.get();
BOOST_TEST(j == 3);
++i;
BOOST_TEST(j == 4);
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_exception_at_thread_exit(exception_ptr p);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/thread/detail/memory.hpp>
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
//void func(boost::promise<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > p)
boost::promise<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > p;
void func()
{
boost::interprocess::unique_ptr<int, boost::default_delete<int> > uptr(new int(5));
p.set_value_at_thread_exit(boost::move(uptr));
}
int main()
{
{
//boost::promise<boost::interprocess::unique_ptr<int, boost::default_delete<int>> > p;
boost::future<boost::interprocess::unique_ptr<int, boost::default_delete<int> > > f = p.get_future();
//boost::thread(func, boost::move(p)).detach();
boost::thread(func).detach();
BOOST_TEST(*f.get() == 5);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,152 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_value(R&& r);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
struct A
{
A() :
value(0)
{
}
A(int i) :
value(i)
{
}
BOOST_THREAD_DELETE_COPY_CTOR(A)
A(A&& rhs)
{
if(rhs.value==0)
throw 9;
else
{
value=rhs.value;
rhs.value=0;
}
}
int value;
};
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
int main()
{
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value(boost::move(i));
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 9);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i(3);
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(boost::move(i));
BOOST_TEST(f.get().value == 3);
try
{
T j(3);
p.set_value(boost::move(j));
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i(3);
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(boost::move(i));
BOOST_TEST(i.value == 0);
boost::promise<T> p2(boost::move(p));
BOOST_TEST(f.get().value == 3);
}
{
typedef A T;
T i(3);
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(boost::move(i));
BOOST_TEST(i.value == 0);
boost::promise<T> p2(boost::move(p));
boost::future<T> f2(boost::move(f));
BOOST_TEST(f2.get().value == 3);
}
{
typedef A T;
T i(3);
boost::promise<T> p;
p.set_value(boost::move(i));
BOOST_TEST(i.value == 0);
boost::promise<T> p2(boost::move(p));
boost::future<T> f = p2.get_future();
BOOST_TEST(f.get().value == 3);
}
{
typedef boost::future<int> T;
boost::promise<int> pi;
T fi=pi.get_future();
pi.set_value(3);
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(boost::move(fi));
boost::future<T> f2(boost::move(f));
BOOST_TEST(f2.get().get() == 3);
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
return boost::report_errors();
}

View File

@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_value_at_thread_exit(const R& r);
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::promise<int> p;
//void func(boost::promise<int> p)
void func()
{
const int i = 5;
p.set_value_at_thread_exit(i);
}
int main()
{
{
//boost::promise<int> p;
boost::future<int> f = p.get_future();
//boost::thread(func, boost::move(p)).detach();
boost::thread(func).detach();
BOOST_TEST(f.get() == 5);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise<void>::set_value_at_thread_exit();
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int i = 0;
boost::promise<void> p;
void func()
{
p.set_value_at_thread_exit();
i = 1;
}
void func2(boost::promise<void> p2)
{
p2.set_value_at_thread_exit();
i = 1;
}
int main()
{
try
{
boost::future<void> f = p.get_future();
boost::thread(func).detach();
f.get();
BOOST_TEST(i == 1);
}
catch(std::exception ex)
{
BOOST_TEST(false);
}
catch(...)
{
BOOST_TEST(false);
}
// BUG when moving promise. fixme
// try
// {
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
// boost::promise<void> p2; // BUG
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
// boost::future<void> f = p2.get_future();
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
// boost::thread(func2, boost::move(p2)).detach(); // BUG
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
// f.get();
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
// BOOST_TEST(i == 1);
// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
//
// }
// catch(std::exception ex)
// {
// std::cout << __FILE__ << ":" << __LINE__ << " " << ex.what() << std::endl;
// BOOST_TEST(false);
// }
// catch(...)
// {
// BOOST_TEST(false);
// }
return boost::report_errors();
}

View File

@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_value(const R& r);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
struct A
{
A()
{
}
A(const A&)
{
throw 10;
}
};
int main()
{
{
typedef int T;
T i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(i);
++i;
BOOST_TEST(f.get() == 3);
--i;
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 10);
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class promise<R>
// void promise<void>::set_value();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
struct A
{
A()
{
}
A(const A&)
{
throw 10;
}
};
int main()
{
{
typedef void T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value();
f.get();
try
{
p.set_value();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class shared_future<R>
// shared_future& operator=(const shared_future&);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}
//#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class shared_future<R>
// shared_future(const future&);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::shared_future < T > f0;
boost::shared_future<T> f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future < T > f0;
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future < T > f0;
boost::shared_future<T> f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}
//#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class shared_future<R>
// shared_future();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::shared_future<int> f;
BOOST_TEST(!f.valid());
}
{
boost::shared_future<int&> f;
BOOST_TEST(!f.valid());
}
{
boost::shared_future<void> f;
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,109 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// class shared_future<R>
// ~shared_future();
#define BOOST_THREAD_VERSION 3
#include <boost/exception/exception.hpp>
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
#endif
int main()
{
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
BOOST_TEST(test_alloc_base::count == 0);
{
typedef int T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<T>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
{
typedef int& T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
{
typedef void T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<T>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
#endif
{
typedef int T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,208 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/shared_future.hpp>
// class shared_future<R>
// const R& shared_future::get();
// R& shared_future<R&>::get();
// void shared_future<void>::get();
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
namespace boost
{
template <typename T>
struct wrap
{
wrap(T const& v) : value(v){}
T value;
};
template <typename T>
exception_ptr make_exception_ptr(T v) {
return copy_exception(wrap<T>(v));
}
}
void func1(boost::promise<int> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_value(3);
}
void func2(boost::promise<int> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_exception(boost::make_exception_ptr(3));
}
int j = 0;
void func3(boost::promise<int&> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
j = 5;
p.set_value(j);
}
void func4(boost::promise<int&> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_exception(boost::make_exception_ptr(3.5));
}
void func5(boost::promise<void> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_value();
}
void func6(boost::promise<void> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
p.set_exception(boost::make_exception_ptr(4));
}
int main()
{
{
typedef int T;
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func1, boost::move(p)).detach();
#else
p.set_value(3);
#endif
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(f.valid());
}
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func2, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(3));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (boost::wrap<int> const& i)
{
BOOST_TEST(i.value == 3);
}
catch (...)
{
BOOST_TEST(false);
}
BOOST_TEST(f.valid());
}
}
{
typedef int& T;
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func3, boost::move(p)).detach();
#else
int j=5;
p.set_value(j);
#endif
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 5);
BOOST_TEST(f.valid());
}
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func4, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (boost::wrap<double> const& i)
{
BOOST_TEST(i.value == 3.5);
}
BOOST_TEST(f.valid());
}
}
typedef void T;
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func5, boost::move(p)).detach();
#else
p.set_value();
#endif
BOOST_TEST(f.valid());
f.get();
BOOST_TEST(f.valid());
}
{
boost::promise<T> p;
boost::shared_future<T> f((p.get_future()));
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func6, boost::move(p)).detach();
#else
p.set_exception(boost::make_exception_ptr(4));
#endif
try
{
BOOST_TEST(f.valid());
f.get();
BOOST_TEST(false);
}
catch (boost::wrap<int> const& i)
{
BOOST_TEST(i.value == 4);
}
catch (...)
{
BOOST_TEST(false);
}
BOOST_TEST(f.valid());
}
return boost::report_errors();
}
#else
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <future>
// class shared_future<R>
// shared_future& shared_future=(shared_future&& rhs);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m0;
boost::mutex m1;
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <future>
// class shared_future<R>
// shared_future(shared_future&& rhs);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m;
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::shared_future<T> f0;
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f0;
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f0;
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}

View File

@@ -18,7 +18,7 @@
// lock_guard(mutex_type& m, adopt_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// lock_guard& operator=(lock_guard const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// lock_guard(lock_guard const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -16,9 +16,9 @@
// template <class Mutex> class lock_guard;
// lock_guard(lock_guard const&) = delete;
// lock_guard(Mutex &);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Lockable>
// lock_guard<Lockable> make_lock_guard(Lockable &, adopt_lock_t);
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#ifdef BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#endif
boost::mutex m;
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
time_point t0 = Clock::now();
time_point t1;
{
m.lock();
auto&& lg = boost::make_lock_guard(m, boost::adopt_lock); (void)lg;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#else
//time_point t0 = Clock::now();
//time_point t1;
{
m.lock();
auto&& lg = boost::make_lock_guard(m, boost::adopt_lock); (void)lg;
//t1 = Clock::now();
}
//ns d = t1 - t0 - ms(250);
//BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#endif
}
#endif
int main()
{
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#endif
m.unlock();
t.join();
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Lockable>
// lock_guard<Lockable> make_lock_guard(Lockable &);
#define BOOST_THREAD_VERSION 4
#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_DONT_PROVIDE_NESTED_LOCKS
#include <boost/thread/detail/log.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#ifdef BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#endif
boost::mutex m;
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
const auto&& lg = boost::make_lock_guard(m); (void)lg;
t1 = Clock::now();
BOOST_THREAD_TRACE;
}
BOOST_THREAD_TRACE;
ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
}
#endif
int main()
{
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
{
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#endif
m.unlock();
t.join();
}
#endif
return boost::report_errors();
}

View File

@@ -25,8 +25,10 @@
// };
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()

View File

@@ -9,10 +9,10 @@
// reverse_lock& operator=(reverse_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/reverse_lock.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/thread/lock_types.hpp>
int main()

View File

@@ -10,10 +10,10 @@
// reverse_lock(reverse_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/reverse_lock.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/thread/lock_types.hpp>
boost::mutex m0;
boost::mutex m1;

View File

@@ -18,9 +18,10 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/reverse_lock.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()

View File

@@ -10,7 +10,7 @@
// unlock_guard(unlock_guard const&) = delete;
#include <boost/thread/reverse_lock.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock(mutex_type& m, adopt_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// shared_lock& operator=(shared_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock(shared_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// shared_lock(shared_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// shared_lock(mutex_type& m, adopt_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Rep, class Period>
// shared_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock(shared_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock& operator=(shared_lock&& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock& operator=(shared_lock&& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock& operator=(shared_lock&& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// explicit shared_lock(Mutex& m);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Clock, class Duration>
// shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// shared_lock(mutex_type& m, try_to_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// void lock();
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
//#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
//#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
//#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// void swap(shared_lock& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/detail/lightweight_test.hpp>
struct shared_mutex

View File

@@ -17,7 +17,7 @@
// template <class Mutex>
// void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/detail/lightweight_test.hpp>
struct shared_mutex

View File

@@ -18,7 +18,7 @@
// void Mutex* release();
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/detail/lightweight_test.hpp>
struct shared_mutex

View File

@@ -18,7 +18,7 @@
// Mutex *mutex() const;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// explicit operator bool() const;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// bool owns_lock() const;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -25,7 +25,7 @@
// };
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/static_assert.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -28,6 +28,7 @@
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/shared_lock_guard.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()

View File

@@ -18,7 +18,7 @@
// unique_lock(mutex_type& m, adopt_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// unique_lock& operator=(unique_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// unique_lock(unique_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// unique_lock(unique_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -18,7 +18,7 @@
// unique_lock(mutex_type& m, adopt_lock_t);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -21,7 +21,7 @@
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_factories.hpp>
// template <class Mutex> class unique_lock;
// unique_lock<Mutex> make_unique_lock(Mutex&, adopt_lock_t);
#include <boost/thread/lock_factories.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
int main()
{
boost::mutex m;
m.lock();
auto lk = boost::make_unique_lock(m, boost::adopt_lock);
BOOST_TEST(lk.mutex() == &m);
BOOST_TEST(lk.owns_lock() == true);
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_factories.hpp>
// template <class Mutex> class unique_lock;
// unique_lock<Mutex> make_unique_lock(Mutex&, defer_lock_t);
// unique_lock(mutex_type& m, adopt_lock_t);
#include <boost/thread/lock_factories.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
int main()
{
boost::mutex m;
m.lock();
auto lk = boost::make_unique_lock(m, boost::defer_lock);
BOOST_TEST(lk.mutex() == &m);
BOOST_TEST(lk.owns_lock() == false);
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_factories.hpp>
// template <class Mutex>
// unique_lock<Mutex> make_unique_lock(Mutex&);
#include <boost/thread/lock_factories.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#else
#endif
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
time_point t0 = Clock::now();
time_point t1;
{
auto&& _ = boost::make_unique_lock(m); (void)_;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#else
//time_point t0 = Clock::now();
//time_point t1;
{
auto _ = boost::make_unique_lock(m); (void)_;
//t1 = Clock::now();
}
//ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
//BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#endif
}
int main()
{
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#else
#endif
m.unlock();
t.join();
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,101 @@
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/locks.hpp>
// template <class Mutex> class unique_lock;
// unique_lock<Mutex> make_unique_lock(Mutex&, try_to_lock_t);
#include <boost/thread/lock_factories.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if ! defined(BOOST_NO_CXX11_AUTO) && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#else
#endif
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
time_point t0 = Clock::now();
{
auto lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
}
{
auto lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
}
{
auto lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
}
while (true)
{
auto lk = boost::make_unique_lock(m, boost::try_to_lock);
if (lk.owns_lock()) break;
}
time_point t1 = Clock::now();
//m.unlock();
ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms
#else
// time_point t0 = Clock::now();
// {
// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
// BOOST_TEST(lk.owns_lock() == false);
// }
// {
// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
// BOOST_TEST(lk.owns_lock() == false);
// }
// {
// boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
// BOOST_TEST(lk.owns_lock() == false);
// }
while (true)
{
auto lk = boost::make_unique_lock(m, boost::try_to_lock);
if (lk.owns_lock()) break;
}
//time_point t1 = Clock::now();
//ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
//BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms
#endif
}
int main()
{
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#else
#endif
m.unlock();
t.join();
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,81 @@
// Copyright (C) 2012 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/lock_factories.hpp>
// template <class Mutex>
// unique_lock<Mutex> make_unique_lock(Mutex&);
#include <boost/thread/lock_factories.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if ! defined(BOOST_NO_CXX11_AUTO) && defined BOOST_NO_CXX11_HDR_TUPLE && ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
boost::mutex m1;
boost::mutex m2;
boost::mutex m3;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#else
#endif
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
time_point t0 = Clock::now();
time_point t1;
{
auto&& _ = boost::make_unique_locks(m1,m2,m3);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#else
//time_point t0 = Clock::now();
//time_point t1;
{
auto&& _ = boost::make_unique_locks(m1,m2,m3);
//t1 = Clock::now();
}
//ns d = t1 - t0 - ms(250);
// This test is spurious as it depends on the time the thread system switches the threads
//BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#endif
}
int main()
{
m1.lock();
m2.lock();
m3.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
boost::this_thread::sleep_for(ms(250));
#else
#endif
m1.unlock();
m2.unlock();
m3.unlock();
t.join();
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -19,7 +19,7 @@
// unique_lock(unique_lock const&) = delete;
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// unique_lock(unique_lock&& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -24,7 +24,7 @@
#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -22,7 +22,7 @@
#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -24,7 +24,7 @@
#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -22,7 +22,7 @@
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// unique_lock(upgrade_lock&& u);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -20,7 +20,7 @@
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -22,7 +22,7 @@
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@@ -19,7 +19,7 @@
// explicit unique_lock(Mutex& m);
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>

Some files were not shown because too many files have changed in this diff Show More