1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-13 01:27:58 -05:00

Initial commit

This commit is contained in:
Crimson-Hawk
2024-03-05 16:42:40 +08:00
commit f1e4595ebf
39576 changed files with 7006612 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
/*
* Permit this Carbon application to launch on OS X
*
* <20> 1997-2000 Metrowerks Corp.
*
* Questions and comments to:
* <mailto:support@metrowerks.com>
* <http://www.metrowerks.com/>
*/
/*----------------------------carb <20> Carbon on OS X launch information --------------------------*/
type 'carb' {
};
resource 'carb'(0) {
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
#ifndef CONDITION_TEST_COMMON_HPP
#define CONDITION_TEST_COMMON_HPP
// Copyright (C) 2007 Anthony Williams
//
// 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>
#include <boost/thread/mutex.hpp>
#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)
{}
struct check_flag
{
bool const& flag;
check_flag(bool const& flag_):
flag(flag_)
{}
bool operator()() const
{
return flag;
}
private:
void operator=(check_flag&);
};
void wait_without_predicate()
{
boost::unique_lock<boost::mutex> lock(mutex);
while(!flag)
{
cond_var.wait(lock);
}
++woken;
}
void wait_with_predicate()
{
boost::unique_lock<boost::mutex> lock(mutex);
cond_var.wait(lock,check_flag(flag));
if(flag)
{
++woken;
}
}
void timed_wait_without_predicate()
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
boost::unique_lock<boost::mutex> lock(mutex);
while(!flag)
{
if(!cond_var.timed_wait(lock,timeout))
{
return;
}
}
++woken;
}
void timed_wait_with_predicate()
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
boost::unique_lock<boost::mutex> lock(mutex);
if(cond_var.timed_wait(lock,timeout,check_flag(flag)) && flag)
{
++woken;
}
}
void relative_timed_wait_with_predicate()
{
boost::unique_lock<boost::mutex> lock(mutex);
if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag)
{
++woken;
}
}
};
#endif

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2014 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/experimental/parallel/v1/exception_list.hpp>
#define BOOST_THREAD_VERSION 4
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <boost/thread/experimental/parallel/v1/exception_list.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
return boost::report_errors();
}

View File

@@ -0,0 +1,295 @@
// Copyright (C) 2014-2015 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/experimental/parallel/v1/exception_list.hpp>
#define BOOST_THREAD_VERSION 4
#define BOOST_THREAD_PROVIDES_EXECUTORS
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <boost/thread/experimental/parallel/v2/task_region.hpp>
#include <string>
#include <boost/detail/lightweight_test.hpp>
#if ! defined BOOST_NO_CXX11_LAMBDAS && defined(BOOST_THREAD_PROVIDES_INVOKE)
using boost::experimental::parallel::v2::task_region;
using boost::experimental::parallel::v2::task_region_handle;
using boost::experimental::parallel::v1::exception_list;
void run_no_exception()
{
std::string s("test");
bool parent_flag = false;
bool task1_flag = false;
bool task2_flag = false;
bool task21_flag = false;
bool task3_flag = false;
task_region([&](task_region_handle& trh)
{
parent_flag = true;
trh.run([&]()
{
task1_flag = true;
std::cout << "task1: " << s << std::endl;
});
trh.run([&]()
{
task2_flag = true;
std::cout << "task2" << std::endl;
task_region([&](task_region_handle& trh)
{
trh.run([&]()
{
task21_flag = true;
std::cout << "task2.1" << std::endl;
});
});
});
int i = 0, j = 10, k = 20;
trh.run([=, &task3_flag]()
{
task3_flag = true;
std::cout << "task3: " << i << " " << j << " " << k << std::endl;
});
std::cout << "parent" << std::endl;
});
BOOST_TEST(parent_flag);
BOOST_TEST(task1_flag);
BOOST_TEST(task2_flag);
BOOST_TEST(task21_flag);
BOOST_TEST(task3_flag);
}
void run_no_exception_wait()
{
std::string s("test");
bool parent_flag = false;
bool wait_flag = false;
bool task1_flag = false;
bool task2_flag = false;
bool task21_flag = false;
bool task3_flag = false;
task_region([&](task_region_handle& trh)
{
parent_flag = true;
trh.run([&]()
{
task1_flag = true;
std::cout << "task1: " << s << std::endl;
});
trh.run([&]()
{
task2_flag = true;
std::cout << "task2" << std::endl;
task_region([&](task_region_handle& trh)
{
trh.run([&]()
{
task21_flag = true;
std::cout << "task2.1" << std::endl;
});
});
});
int i = 0, j = 10, k = 20;
trh.run([=, &task3_flag]()
{
task3_flag = true;
std::cout << "task3: " << i << " " << j << " " << k << std::endl;
});
std::cout << "before" << std::endl;
trh.wait();
wait_flag = true;
std::cout << "parent" << std::endl;
});
BOOST_TEST(parent_flag);
BOOST_TEST(wait_flag);
BOOST_TEST(task1_flag);
BOOST_TEST(task2_flag);
BOOST_TEST(task21_flag);
BOOST_TEST(task3_flag);
}
void run_exception_1()
{
try
{
task_region([](task_region_handle& trh)
{
trh.run([]()
{
std::cout << "task1" << std::endl;
throw 1;
});
boost::this_thread::sleep_for(boost::chrono::seconds(1));
trh.run([]()
{
std::cout << "task3" << std::endl;
});
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
BOOST_TEST(false);
#endif
});
BOOST_TEST(false);
}
catch (exception_list const& e)
{
BOOST_TEST_EQ(e.size(), 1u);
}
catch (...)
{
BOOST_TEST(false);
}
}
void run_exception()
{
try
{
task_region([](task_region_handle& trh)
{
trh.run([]()
{
std::cout << "task1" << std::endl;
throw 1;
});
trh.run([]()
{
std::cout << "task2" << std::endl;
throw 2;
});
boost::this_thread::sleep_for(boost::chrono::seconds(1));
trh.run([]()
{
std::cout << "task3" << std::endl;
throw 3;
});
std::cout << "parent" << std::endl;
throw 100;
});
BOOST_TEST(false);
}
catch (exception_list const& el)
{
BOOST_TEST(el.size() >= 1u);
for (boost::exception_ptr const& e: el)
{
try {
boost::rethrow_exception(e);
}
catch (boost::exception&)
{
BOOST_TEST(true);
}
catch (int i) // this doesn't works yet
{
BOOST_TEST((i == 1) || (i == 2) || (i == 3));
}
catch (...)
{
BOOST_TEST(false);
}
}
}
catch (...)
{
BOOST_TEST(false);
}
}
void run_nested_exception()
{
std::string s("test");
bool parent_flag = false;
bool task1_flag = false;
bool task2_flag = false;
bool task21_flag = false;
bool task3_flag = false;
try
{
task_region([&](task_region_handle& trh)
{
parent_flag = true;
trh.run([&]()
{
task1_flag = true;
std::cout << "task1: " << s << std::endl;
});
trh.run([&]()
{
task2_flag = true;
std::cout << "task2" << std::endl;
task_region([&](task_region_handle& trh)
{
trh.run([&]()
{
task21_flag = true;
std::cout << "task2.1" << std::endl;
throw 21;
});
});
});
int i = 0, j = 10, k = 20;
trh.run([=, &task3_flag]()
{
task3_flag = true;
std::cout << "task3: " << i << " " << j << " " << k << std::endl;
});
std::cout << "parent" << std::endl;
});
}
catch (exception_list const& el)
{
BOOST_TEST(el.size() == 1u);
for (boost::exception_ptr const& e: el)
{
try {
boost::rethrow_exception(e);
}
catch (int i) // this doesn't works yet
{
BOOST_TEST_EQ(i, 21);
}
catch (boost::exception&)
{
BOOST_TEST(true);
}
catch (...)
{
BOOST_TEST(false);
}
}
}
catch (...)
{
BOOST_TEST(false);
}
BOOST_TEST(parent_flag);
BOOST_TEST(task1_flag);
BOOST_TEST(task2_flag);
BOOST_TEST(task21_flag);
}
int main()
{
run_no_exception();
run_no_exception_wait();
run_exception();
run_exception_1();
run_nested_exception();
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoke.hpp>
#include <boost/thread/detail/invoke.hpp>
#include <boost/detail/lightweight_test.hpp>
int f()
{
return 1;
}
struct A_int_0
{
A_int_0()
{
}
int operator()()
{
return 4;
}
int operator()() const
{
return 5;
}
};
int main()
{
const A_int_0 ca;
A_int_0 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST_EQ(boost::detail::invoke(f), 1);
BOOST_TEST_EQ(boost::detail::invoke(&f), 1);
BOOST_TEST_EQ(boost::detail::invoke(A_int_0()), 4);
BOOST_TEST_EQ(boost::detail::invoke(a), 4);
BOOST_TEST_EQ(boost::detail::invoke(ca), 5);
#endif
BOOST_TEST_EQ(boost::detail::invoke<int>(f), 1);
BOOST_TEST_EQ(boost::detail::invoke<int>(&f), 1);
BOOST_TEST_EQ(A_int_0()(), 4);
#if defined BOOST_THREAD_PROVIDES_INVOKE || ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 4);
#else
//BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 5);
#endif
BOOST_TEST_EQ(a(), 4);
BOOST_TEST_EQ(boost::detail::invoke<int>(a), 4);
BOOST_TEST_EQ(ca(), 5);
BOOST_TEST_EQ(boost::detail::invoke<int>(ca), 5);
return boost::report_errors();
}

View File

@@ -0,0 +1,336 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoke.hpp>
#include <boost/thread/detail/invoke.hpp>
#include <boost/detail/lightweight_test.hpp>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {count += 2;}
};
void
test_void_1()
{
int save_count = count;
// function
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
int i = 2;
boost::detail::invoke(f_void_1, i);
BOOST_TEST(count == save_count + 2);
save_count = count;
}
#endif
{
int i = 2;
boost::detail::invoke<void>(f_void_1, i);
BOOST_TEST(count == save_count + 2);
save_count = count;
}
// function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoke(fp, i);
BOOST_TEST(count == save_count+3);
save_count = count;
}
#endif
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoke<void>(fp, i);
BOOST_TEST(count == save_count+3);
save_count = count;
}
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoke(fp, i);
BOOST_TEST(count == save_count+3);
save_count = count;
}
#endif
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoke<void>(fp, i);
BOOST_TEST(count == save_count+3);
save_count = count;
}
// functor
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
A_void_1 a0;
int i = 4;
boost::detail::invoke(a0, i);
BOOST_TEST(count == save_count+4);
save_count = count;
}
#endif
{
A_void_1 a0;
int i = 4;
boost::detail::invoke<void>(a0, i);
BOOST_TEST(count == save_count+4);
save_count = count;
}
// member function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (A_void_1::*fp)() = &A_void_1::mem1;
A_void_1 a;
boost::detail::invoke(fp, a);
BOOST_TEST(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoke(fp, ap);
BOOST_TEST(count == save_count+1);
save_count = count;
}
#endif
{
void (A_void_1::*fp)() = &A_void_1::mem1;
A_void_1 a;
boost::detail::invoke<void>(fp, a);
BOOST_TEST(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoke<void>(fp, ap);
BOOST_TEST(count == save_count+1);
save_count = count;
}
// const member function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
A_void_1 a;
boost::detail::invoke(fp, a);
BOOST_TEST(count == save_count+2);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoke(fp, ap);
BOOST_TEST(count == save_count+2);
save_count = count;
}
#endif
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
A_void_1 a;
boost::detail::invoke<void>(fp, a);
BOOST_TEST(count == save_count+2);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoke<void>(fp, ap);
BOOST_TEST(count == save_count+2);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
int i = 2;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(f_int_1, i) == 3);
#endif
BOOST_TEST(boost::detail::invoke<int>(f_int_1, i) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
int i = 3;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(fp, i) == 4);
#endif
BOOST_TEST(boost::detail::invoke<int>(fp, i) == 4);
}
// functor
{
int i = 4;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(A_int_1(), i) == 3);
#endif
const A_int_1 ca;
A_int_1 a;
BOOST_TEST(boost::detail::invoke<int>(a, i) == 3);
//BOOST_TEST(boost::detail::invoke<int>(ca, i) == 3);
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke<int>(A_int_1(), i) == 3);
#endif
}
// member function pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, a) == 3);
#endif
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, a) == 3);
A_int_1* ap = &a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, ap) == 3);
#endif
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, ap) == 3);
}
// const member function pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, A_int_1()) == 4);
#endif
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem2, A_int_1()) == 4);
A_int_1* ap = &a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, ap) == 4);
#endif
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem2, ap) == 4);
}
// member data pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 5);
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, a) == 5);
#endif
#if defined BOOST_THREAD_PROVIDES_INVOKE
A_int_1* ap = &a;
boost::detail::invoke(&A_int_1::data_, a) = 6;
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 6);
boost::detail::invoke<int>(&A_int_1::data_, a) = 6;
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, a) == 6);
#endif
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, ap) == 6);
boost::detail::invoke(&A_int_1::data_, ap) = 7;
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, ap) == 7);
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, ap) == 7);
boost::detail::invoke<int>(&A_int_1::data_, ap) = 8;
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, ap) == 8);
#endif
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
int i = 2;
int j = 3;
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoke(f_void_2, i, j);
BOOST_TEST(count == save_count+5);
save_count = count;
#endif
boost::detail::invoke<void>(f_void_2, i, j);
BOOST_TEST(count == save_count+5);
save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
int j = 3;
boost::detail::invoke(&A_void_2::mem1, A_void_2(), j);
BOOST_TEST(count == save_count+3);
save_count = count;
boost::detail::invoke<void>(&A_void_2::mem1, A_void_2(), j);
BOOST_TEST(count == save_count+3);
save_count = count;
#endif
// A_void_2 a2;
// boost::detail::invoke<void>(&A_void_2::mem1, a2, j);
// BOOST_TEST(count == save_count+3);
// save_count = count;
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
return boost::report_errors();
}

View File

@@ -0,0 +1,227 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoke.hpp>
#include <boost/thread/detail/invoke.hpp>
#include <boost/detail/lightweight_test.hpp>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {count += 2;}
};
void
test_void_1()
{
int save_count = count;
// function
{
boost::detail::invoke(f_void_1, 2);
BOOST_TEST(count == save_count + 2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
boost::detail::invoke(fp, 3);
BOOST_TEST(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoke(a0, 4);
BOOST_TEST(count == save_count+4);
save_count = count;
#endif
boost::detail::invoke<void>(a0, 4);
BOOST_TEST(count == save_count+4);
save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
void (A_void_1::*fp)() = &A_void_1::mem1;
boost::detail::invoke(fp, A_void_1());
BOOST_TEST(count == save_count+1);
save_count = count;
//BUG
boost::detail::invoke<void>(fp, A_void_1());
BOOST_TEST(count == save_count+1);
save_count = count;
#endif
#if defined BOOST_THREAD_PROVIDES_INVOKE
A_void_1 a;
boost::detail::invoke(fp, &a);
BOOST_TEST(count == save_count+1);
save_count = count;
//BUG
boost::detail::invoke<int>(fp, &a);
BOOST_TEST(count == save_count+1);
save_count = count;
#endif
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
boost::detail::invoke(fp, A_void_1());
BOOST_TEST(count == save_count+2);
save_count = count;
A_void_1 a;
boost::detail::invoke(fp, &a);
BOOST_TEST(count == save_count+2);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
BOOST_TEST(boost::detail::invoke(f_int_1, 2) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
BOOST_TEST(boost::detail::invoke(fp, 3) == 4);
}
// functor
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(A_int_1(), 4) == 3);
BOOST_TEST(boost::detail::invoke<int>(A_int_1(), 4) == 3);
#endif
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, A_int_1()) == 3);
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, A_int_1()) == 3);
#endif
A_int_1 a;
BOOST_TEST(boost::detail::invoke(&A_int_1::mem1, &a) == 3);
}
// const member function pointer
{
BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, A_int_1()) == 4);
A_int_1 a;
BOOST_TEST(boost::detail::invoke(&A_int_1::mem2, &a) == 4);
}
// member data pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, A_int_1()) == 5);
BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, A_int_1()) == 5);
A_int_1 a;
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 5);
boost::detail::invoke(&A_int_1::data_, a) = 6;
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, a) == 6);
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, &a) == 6);
boost::detail::invoke(&A_int_1::data_, &a) = 7;
BOOST_TEST(boost::detail::invoke(&A_int_1::data_, &a) == 7);
#endif
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
boost::detail::invoke(f_void_2, 2, 3);
BOOST_TEST(count == save_count+5);
save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoke(&A_void_2::mem1, A_void_2(), 3);
BOOST_TEST(count == save_count+3);
save_count = count;
boost::detail::invoke<void>(&A_void_2::mem1, A_void_2(), 3);
BOOST_TEST(count == save_count+3);
save_count = count;
#endif
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoker.hpp>
#include <boost/thread/detail/invoker.hpp>
#include <boost/detail/lightweight_test.hpp>
int f()
{
return 1;
}
struct A_int_0
{
A_int_0()
{
}
int operator()()
{
return 4;
}
int operator()() const
{
return 5;
}
};
int main()
{
const A_int_0 ca;
A_int_0 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST_EQ(boost::detail::invoker<int(*)()>(f)(), 1);
BOOST_TEST_EQ(boost::detail::invoker<int(*)()>(&f)(), 1);
BOOST_TEST_EQ(boost::detail::invoker<A_int_0>(A_int_0())(), 4);
BOOST_TEST_EQ(boost::detail::invoker<A_int_0>(a)(), 4);
BOOST_TEST_EQ(boost::detail::invoker<const A_int_0>(ca)(), 5);
#endif
//BOOST_TEST_EQ(boost::detail::invoker<int>(f), 1);
//BOOST_TEST_EQ(boost::detail::invoker<int>(&f), 1);
BOOST_TEST_EQ(A_int_0()(), 4);
#if defined BOOST_THREAD_PROVIDES_INVOKE || ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
//BOOST_TEST_EQ(boost::detail::invoker<int>(A_int_0()), 4);
#else
//BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 5);
#endif
//BOOST_TEST_EQ(a(), 4);
//BOOST_TEST_EQ(boost::detail::invoke<int>(a), 4);
//BOOST_TEST_EQ(ca(), 5);
//BOOST_TEST_EQ(boost::detail::invoke<int>(ca), 5);
return boost::report_errors();
}

View File

@@ -0,0 +1,342 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoker.hpp>
#include <boost/thread/detail/invoker.hpp>
#include <boost/detail/lightweight_test.hpp>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
typedef void result_type;
void operator()(int i)
{
count += i;
}
void mem1() {
std::cout << "mem1 " << count << std::endl;
++count;
std::cout << "mem1 " << count << std::endl;
}
void mem2() const {count += 2;}
};
void
test_void_1()
{
int save_count = count;
// function
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
int i = 2;
boost::detail::invoker<void(*)(int), int>(f_void_1, i)();
BOOST_TEST(count == save_count + 2);
save_count = count;
}
#endif
// {
// int i = 2;
// boost::detail::invoke<void>(f_void_1, i);
// BOOST_TEST(count == save_count + 2);
// save_count = count;
// }
// function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoker<void(*)(int), int>(fp, i)();
BOOST_TEST(count == save_count+3);
save_count = count;
}
#endif
// {
// void (*fp)(int) = f_void_1;
// int i = 3;
// boost::detail::invoke<void>(fp, i);
// BOOST_TEST(count == save_count+3);
// save_count = count;
// }
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (*fp)(int) = f_void_1;
int i = 3;
boost::detail::invoker<void(*)(int), int>(fp, i)();
BOOST_TEST(count == save_count+3);
save_count = count;
}
#endif
// {
// void (*fp)(int) = f_void_1;
// int i = 3;
// boost::detail::invoke<void>(fp, i);
// BOOST_TEST(count == save_count+3);
// save_count = count;
// }
// functor
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
A_void_1 a0;
int i = 4;
boost::detail::invoker<A_void_1, int>(a0, i)();
BOOST_TEST(count == save_count+4);
save_count = count;
}
#endif
// {
// A_void_1 a0;
// int i = 4;
// boost::detail::invoke<void>(a0, i);
// BOOST_TEST(count == save_count+4);
// save_count = count;
// }
// member function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (A_void_1::*fp)() = &A_void_1::mem1;
A_void_1 a;
//BUG
boost::detail::invoker<void (A_void_1::*)(), A_void_1>(fp, a)();
BOOST_TEST_EQ(count, save_count+1);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoker<void (A_void_1::*)(), A_void_1*>(fp, ap)();
BOOST_TEST_EQ(count, save_count+1);
save_count = count;
}
#endif
// {
// void (A_void_1::*fp)() = &A_void_1::mem1;
// A_void_1 a;
// boost::detail::invoke<void>(fp, a);
// BOOST_TEST(count == save_count+1);
// save_count = count;
// A_void_1* ap = &a;
// boost::detail::invoke<void>(fp, ap);
// BOOST_TEST(count == save_count+1);
// save_count = count;
// }
// const member function pointer
#if defined BOOST_THREAD_PROVIDES_INVOKE
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
A_void_1 a;
boost::detail::invoker<void (A_void_1::*)() const, A_void_1>(fp, a)();
BOOST_TEST(count == save_count+2);
save_count = count;
A_void_1* ap = &a;
boost::detail::invoker<void (A_void_1::*)() const, A_void_1*>(fp, ap)();
BOOST_TEST_EQ(count, save_count+2);
save_count = count;
}
#endif
// {
// void (A_void_1::*fp)() const = &A_void_1::mem2;
// A_void_1 a;
// boost::detail::invoke<void>(fp, a);
// BOOST_TEST(count == save_count+2);
// save_count = count;
// A_void_1* ap = &a;
// boost::detail::invoke<void>(fp, ap);
// BOOST_TEST(count == save_count+2);
// save_count = count;
// }
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
int i = 2;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int(*)(int), int>(f_int_1, i)() == 3));
#endif
// BOOST_TEST(boost::detail::invoke<int>(f_int_1, i) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
int i = 3;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (*)(int), int>(fp, i)() == 4));
#endif
// BOOST_TEST(boost::detail::invoke<int>(fp, i) == 4);
}
// functor
{
int i = 4;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<A_int_1, int>(A_int_1(), i)() == 3));
#endif
// const A_int_1 ca;
// A_int_1 a;
// BOOST_TEST(boost::detail::invoke<int>(a, i) == 3);
// //BOOST_TEST(boost::detail::invoke<int>(ca, i) == 3);
//#if defined BOOST_THREAD_PROVIDES_INVOKE
// BOOST_TEST(boost::detail::invoke<int>(A_int_1(), i) == 3);
//#endif
}
// member function pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)(), A_int_1>(&A_int_1::mem1, a)() == 3));
#endif
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, a) == 3);
A_int_1* ap = &a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)(), A_int_1*>(&A_int_1::mem1, ap)() == 3));
#endif
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, ap) == 3);
}
// const member function pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)() const, A_int_1>(&A_int_1::mem2, A_int_1())() == 4));
#endif
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem2, A_int_1()) == 4);
A_int_1* ap = &a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)() const, A_int_1*>(&A_int_1::mem2, ap)() == 4));
#endif
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem2, ap) == 4);
}
// member data pointer
{
A_int_1 a;
#if defined BOOST_THREAD_PROVIDES_INVOKE
// BUG
//BOOST_TEST(boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a) == 5);
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, a) == 5);
#endif
//#if defined BOOST_THREAD_PROVIDES_INVOKE
// A_int_1* ap = &a;
//
// boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a) = 6;
// BOOST_TEST(boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a) == 6);
//
//// boost::detail::invoke<int>(&A_int_1::data_, a) = 6;
//// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, a) == 6);
//
//#endif
//
//#if defined BOOST_THREAD_PROVIDES_INVOKE
// BOOST_TEST(boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, ap) == 6);
// boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, ap) = 7;
// BOOST_TEST(boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, ap) == 7);
//
//// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, ap) == 7);
//// boost::detail::invoke<int>(&A_int_1::data_, ap) = 8;
//// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, ap) == 8);
//#endif
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
int i = 2;
int j = 3;
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoke(f_void_2, i, j);
BOOST_TEST(count == save_count+5);
save_count = count;
#endif
// boost::detail::invoke<void>(f_void_2, i, j);
// BOOST_TEST(count == save_count+5);
// save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
int j = 3;
boost::detail::invoke(&A_void_2::mem1, A_void_2(), j);
BOOST_TEST(count == save_count+3);
save_count = count;
// boost::detail::invoke<void>(&A_void_2::mem1, A_void_2(), j);
// BOOST_TEST(count == save_count+3);
// save_count = count;
#endif
// A_void_2 a2;
// boost::detail::invoke<void>(&A_void_2::mem1, a2, j);
// BOOST_TEST(count == save_count+3);
// save_count = count;
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
return boost::report_errors();
}

View File

@@ -0,0 +1,230 @@
//===----------------------------------------------------------------------===//
//
// 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) 2014 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/detail/invoker.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
//#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <boost/thread/detail/invoker.hpp>
#include <boost/detail/lightweight_test.hpp>
int count = 0;
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
typedef void result_type;
void operator()(int i)
{
count += i;
}
void mem1() {++count;}
void mem2() const {count += 2;}
};
void
test_void_1()
{
int save_count = count;
// function
{
boost::detail::invoker<void(*)(int), int>(f_void_1, 2)();
BOOST_TEST(count == save_count + 2);
save_count = count;
}
// function pointer
{
void (*fp)(int) = f_void_1;
boost::detail::invoker<void(*)(int), int>(fp, 3)();
BOOST_TEST(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoker<A_void_1, int>(a0, 4)();
BOOST_TEST(count == save_count+4);
save_count = count;
#endif
// boost::detail::invoke<void>(a0, 4);
// BOOST_TEST(count == save_count+4);
// save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
void (A_void_1::*fp)() = &A_void_1::mem1;
boost::detail::invoker<void (A_void_1::*)(), A_void_1>(fp, A_void_1())();
BOOST_TEST(count == save_count+1);
save_count = count;
#endif
// boost::detail::invoke<void>(fp, A_void_1());
// BOOST_TEST(count == save_count+1);
// save_count = count;
#if defined BOOST_THREAD_PROVIDES_INVOKE
A_void_1 a;
boost::detail::invoker<void (A_void_1::*)(), A_void_1*>(fp, &a)();
BOOST_TEST(count == save_count+1);
save_count = count;
#endif
// boost::detail::invoke<int>(fp, &a);
// BOOST_TEST(count == save_count+1);
// save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
boost::detail::invoker<void (A_void_1::*)() const, A_void_1>(fp, A_void_1())();
BOOST_TEST(count == save_count+2);
save_count = count;
A_void_1 a;
boost::detail::invoker<void (A_void_1::*)() const, A_void_1*>(fp, &a)();
BOOST_TEST(count == save_count+2);
save_count = count;
}
}
// 1 arg, return int
int f_int_1(int i)
{
return i + 1;
}
struct A_int_1
{
A_int_1() : data_(5) {}
int operator()(int i)
{
return i - 1;
}
int mem1() {return 3;}
int mem2() const {return 4;}
int data_;
};
void
test_int_1()
{
// function
{
BOOST_TEST((boost::detail::invoker<int (*)(int), int>(f_int_1, 2)() == 3));
}
// function pointer
{
int (*fp)(int) = f_int_1;
BOOST_TEST((boost::detail::invoker<int (*)(int), int>(fp, 3)() == 4));
}
// functor
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<A_int_1, int>(A_int_1(), 4)() == 3));
// BOOST_TEST(boost::detail::invoke<int>(A_int_1(), 4) == 3);
#endif
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)(),A_int_1>(&A_int_1::mem1, A_int_1())() == 3));
// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::mem1, A_int_1()) == 3);
#endif
A_int_1 a;
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)(), A_int_1*>(&A_int_1::mem1, &a)() == 3));
}
// const member function pointer
{
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)() const, A_int_1>(&A_int_1::mem2, A_int_1())() == 4));
A_int_1 a;
BOOST_TEST((boost::detail::invoker<int (A_int_1::*)() const, A_int_1*>(&A_int_1::mem2, &a)() == 4));
}
// member data pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
// BOOST_TEST((boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, A_int_1())() == 5));
//// BOOST_TEST(boost::detail::invoke<int>(&A_int_1::data_, A_int_1()) == 5);
// A_int_1 a;
// BOOST_TEST((boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a)() == 5));
// boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a)() = 6;
// BOOST_TEST((boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, a)() == 6));
// BOOST_TEST((boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, &a)() == 6));
// boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, &a)() = 7;
// BOOST_TEST((boost::detail::invoker<int A_int_1::*>(&A_int_1::data_, &a)() == 7));
#endif
}
}
// 2 arg, return void
void f_void_2(int i, int j)
{
count += i+j;
}
struct A_void_2
{
void operator()(int i, int j)
{
count += i+j;
}
void mem1(int i) {count += i;}
void mem2(int i) const {count += i;}
};
void
test_void_2()
{
int save_count = count;
// function
{
boost::detail::invoke(f_void_2, 2, 3);
BOOST_TEST(count == save_count+5);
save_count = count;
}
// member function pointer
{
#if defined BOOST_THREAD_PROVIDES_INVOKE
boost::detail::invoke(&A_void_2::mem1, A_void_2(), 3);
BOOST_TEST(count == save_count+3);
save_count = count;
boost::detail::invoke<void>(&A_void_2::mem1, A_void_2(), 3);
BOOST_TEST(count == save_count+3);
save_count = count;
#endif
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
return boost::report_errors();
}

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2008 Anthony Williams
//
// 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/thread.hpp>
void do_nothing()
{}
void test()
{
boost::thread t1(do_nothing);
boost::thread t2;
t2=t1;
}
#include "./remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2008 Anthony Williams
//
// 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/thread.hpp>
void do_nothing()
{}
void test()
{
boost::thread t1(do_nothing);
boost::thread t2(t1);
}
#include "./remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2008 Anthony Williams
//
// 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/thread.hpp>
void remove_unused_warning()
{
//../../../boost/system/error_code.hpp:214:36: warning: 'boost::system::posix_category' defined but not used [-Wunused-variable]
//../../../boost/system/error_code.hpp:215:36: warning: 'boost::system::errno_ecat' defined but not used [-Wunused-variable]
//../../../boost/system/error_code.hpp:216:36: warning: 'boost::system::native_ecat' defined but not used [-Wunused-variable]
//(void)boost::system::posix_category;
//(void)boost::system::errno_ecat;
//(void)boost::system::native_ecat;
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright Andrey Semashev 2019.
* 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)
*/
/*!
* \file self_contained_header.cpp
* \author Andrey Semashev
* \date 2019-01-19
*
* \brief This file contains a test boilerplate for checking that every public header is self-contained and does not have any missing #includes.
*/
#if defined(BOOST_THREAD_TEST_POST_WINDOWS_H)
#include <windows.h>
#endif
#define BOOST_THREAD_TEST_INCLUDE_HEADER() <boost/thread/BOOST_THREAD_TEST_HEADER>
#include BOOST_THREAD_TEST_INCLUDE_HEADER()
int main(int, char*[])
{
return 0;
}

View File

@@ -0,0 +1,145 @@
#ifndef SHARED_MUTEX_LOCKING_THREAD_HPP
#define SHARED_MUTEX_LOCKING_THREAD_HPP
// (C) Copyright 2008 Anthony Williams
//
// 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/config.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/shared_mutex.hpp>
template<typename lock_type>
class locking_thread
{
boost::shared_mutex& rw_mutex;
unsigned& unblocked_count;
boost::condition_variable& unblocked_condition;
unsigned& simultaneous_running_count;
unsigned& max_simultaneous_running;
boost::mutex& unblocked_count_mutex;
boost::mutex& finish_mutex;
public:
locking_thread(boost::shared_mutex& rw_mutex_,
unsigned& unblocked_count_,
boost::mutex& unblocked_count_mutex_,
boost::condition_variable& unblocked_condition_,
boost::mutex& finish_mutex_,
unsigned& simultaneous_running_count_,
unsigned& max_simultaneous_running_):
rw_mutex(rw_mutex_),
unblocked_count(unblocked_count_),
unblocked_condition(unblocked_condition_),
simultaneous_running_count(simultaneous_running_count_),
max_simultaneous_running(max_simultaneous_running_),
unblocked_count_mutex(unblocked_count_mutex_),
finish_mutex(finish_mutex_)
{}
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
locking_thread(locking_thread const&) = default;
#endif
void operator()()
{
// acquire lock
lock_type lock(rw_mutex);
// increment count to show we're unblocked
{
boost::unique_lock<boost::mutex> ublock(unblocked_count_mutex);
++unblocked_count;
unblocked_condition.notify_one();
++simultaneous_running_count;
if(simultaneous_running_count>max_simultaneous_running)
{
max_simultaneous_running=simultaneous_running_count;
}
}
// wait to finish
boost::unique_lock<boost::mutex> finish_lock(finish_mutex);
{
boost::unique_lock<boost::mutex> ublock(unblocked_count_mutex);
--simultaneous_running_count;
}
}
private:
void operator=(locking_thread&);
};
class simple_writing_thread
{
boost::shared_mutex& rwm;
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_,
boost::mutex& unblocked_mutex_,
unsigned& unblocked_count_):
rwm(rwm_),finish_mutex(finish_mutex_),
unblocked_mutex(unblocked_mutex_),unblocked_count(unblocked_count_)
{}
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
simple_writing_thread(simple_writing_thread const&) = default;
#endif
void operator()()
{
boost::unique_lock<boost::shared_mutex> lk(rwm);
{
boost::unique_lock<boost::mutex> ulk(unblocked_mutex);
++unblocked_count;
}
boost::unique_lock<boost::mutex> flk(finish_mutex);
}
};
class simple_reading_thread
{
boost::shared_mutex& rwm;
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_,
boost::mutex& unblocked_mutex_,
unsigned& unblocked_count_):
rwm(rwm_),finish_mutex(finish_mutex_),
unblocked_mutex(unblocked_mutex_),unblocked_count(unblocked_count_)
{}
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
simple_reading_thread(simple_reading_thread const&) = default;
#endif
void operator()()
{
boost::shared_lock<boost::shared_mutex> lk(rwm);
{
boost::unique_lock<boost::mutex> ulk(unblocked_mutex);
++unblocked_count;
}
boost::unique_lock<boost::mutex> flk(finish_mutex);
}
};
#endif

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable& operator=(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
void fail()
{
boost::condition_variable cv0;
boost::condition_variable cv1;
cv1 = cv0;
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/detail/lightweight_test.hpp>
void fail()
{
boost::condition_variable cv0;
boost::condition_variable cv1(cv0);
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
boost::condition_variable cv0;
return boost::report_errors();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/locks.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::condition_variable* cv;
boost::mutex m;
typedef boost::unique_lock<boost::mutex> Lock;
bool f_ready = false;
bool g_ready = false;
void f()
{
Lock lk(m);
f_ready = true;
cv->notify_one();
cv->wait(lk);
delete cv;
}
void g()
{
Lock lk(m);
g_ready = true;
cv->notify_one();
while (!f_ready)
{
cv->wait(lk);
}
cv->notify_one();
}
int main()
{
cv = new boost::condition_variable;
boost::thread th2(g);
Lock lk(m);
while (!g_ready)
{
cv->wait(lk);
}
lk.unlock();
boost::thread th1(f);
th1.join();
th2.join();
return boost::report_errors();
}

View File

@@ -0,0 +1,241 @@
//===----------------------------------------------------------------------===//
//
// 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) 2017 Austin J. Beer
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <iostream>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
// Summary of each test:
// 1. Start the test thread and wait for it to start up.
// The test thread waits for the flag to be set using a large timeout.
// 2. The main thread takes the lock and then sleeps for a long time while holding
// the lock before setting the flag and calling notify_one(). If the wait
// function being tested is polling pthread_cond_timedwait() internally, any
// notifications sent after pthread_cond_timedwait() times out but before it can
// reacquire the lock may be "lost". pthread_cond_timedwait() will report that
// it timed out and the wait function may incorrectly assume that no
// notification was received. This test ensures that that doesn't happen.
// 3. Measure how it takes the test thread to return. If it received the
// notification, it will return fairly quickly. If it missed the notification,
// the test thread won't return until the wait function being tested times out.
//------------------------------------------------------------------------------
boost::condition_variable cv;
boost::mutex mut;
bool flag;
bool waiting;
bool flagIsSet()
{
return flag;
}
bool threadIsWaiting()
{
return waiting;
}
//------------------------------------------------------------------------------
#ifdef BOOST_THREAD_USES_DATETIME
boost::posix_time::milliseconds posix_wait_time(1000);
template <typename F>
void test_posix_wait_function(F f)
{
flag = false;
waiting = false;
boost::thread t(f);
while (!threadIsWaiting())
{
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
boost::unique_lock<boost::mutex> lk(mut);
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
boost::posix_time::ptime t0 = boost::posix_time::microsec_clock::universal_time();
flag = true;
cv.notify_one();
lk.unlock();
t.join();
boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::universal_time();
BOOST_TEST(t1 - t0 < boost::posix_time::milliseconds(250));
}
//------------------------------------------------------------------------------
void timed_wait_absolute_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.timed_wait(lk, boost::posix_time::microsec_clock::universal_time() + posix_wait_time);
}
}
void timed_wait_absolute_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.timed_wait(lk, boost::posix_time::microsec_clock::universal_time() + posix_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void timed_wait_relative_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.timed_wait(lk, posix_wait_time);
}
}
void timed_wait_relative_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.timed_wait(lk, posix_wait_time, flagIsSet);
}
#else
#error "Test not applicable: BOOST_THREAD_USES_DATETIME not defined for this platform as not supported"
#endif
//------------------------------------------------------------------------------
#ifdef BOOST_THREAD_USES_CHRONO
boost::chrono::milliseconds chrono_wait_time(1000);
template <typename F>
void test_chrono_wait_function(F f)
{
flag = false;
waiting = false;
boost::thread t(f);
while (!threadIsWaiting())
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
}
boost::unique_lock<boost::mutex> lk(mut);
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
boost::chrono::steady_clock::time_point t0 = boost::chrono::steady_clock::now();
flag = true;
cv.notify_one();
lk.unlock();
t.join();
boost::chrono::steady_clock::time_point t1 = boost::chrono::steady_clock::now();
BOOST_TEST(t1 - t0 < boost::chrono::milliseconds(250));
}
//------------------------------------------------------------------------------
void wait_until_system_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_until(lk, boost::chrono::system_clock::now() + chrono_wait_time);
}
}
void wait_until_system_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_until(lk, boost::chrono::system_clock::now() + chrono_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void wait_until_steady_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_until(lk, boost::chrono::steady_clock::now() + chrono_wait_time);
}
}
void wait_until_steady_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_until(lk, boost::chrono::steady_clock::now() + chrono_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void wait_for_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_for(lk, chrono_wait_time);
}
}
void wait_for_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_for(lk, chrono_wait_time, flagIsSet);
}
#else
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif
//------------------------------------------------------------------------------
int main()
{
#ifdef BOOST_THREAD_USES_DATETIME
test_posix_wait_function(timed_wait_absolute_without_pred);
test_posix_wait_function(timed_wait_absolute_with_pred);
test_posix_wait_function(timed_wait_relative_without_pred);
test_posix_wait_function(timed_wait_relative_with_pred);
#endif
#ifdef BOOST_THREAD_USES_CHRONO
test_chrono_wait_function(wait_until_system_without_pred);
test_chrono_wait_function(wait_until_system_with_pred);
test_chrono_wait_function(wait_until_steady_without_pred);
test_chrono_wait_function(wait_until_steady_with_pred);
test_chrono_wait_function(wait_for_without_pred);
test_chrono_wait_function(wait_for_with_pred);
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/static_assert.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
#if defined BOOST_THREAD_DEFINES_CONDITION_VARIABLE_NATIVE_HANDLE
//BOOST_STATIC_ASSERT((boost::is_same<boost::condition_variable::native_handle_type, pthread_cond_t*>::value));
boost::condition_variable cv;
boost::condition_variable::native_handle_type h = cv.native_handle();
BOOST_TEST(h != 0);
#else
#error "Test not applicable: BOOST_THREAD_DEFINES_CONDITION_VARIABLE_NATIVE_HANDLE not defined for this platform as not supported"
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,116 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <iostream>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
boost::condition_variable cv;
boost::mutex mut;
int test1 = 0;
int test2 = 0;
int runs = 0;
typedef boost::chrono::steady_clock Clock;
typedef boost::chrono::milliseconds milliseconds;
typedef boost::chrono::nanoseconds nanoseconds;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
try {
boost::unique_lock<boost::mutex> lk(mut);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + milliseconds(250);
while (test2 == 0 && cv.wait_for(lk, t - Clock::now()) == boost::cv_status::no_timeout) {}
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < max_diff);
assert(test2 != 0);
}
else
{
nanoseconds d = t1 - t0 - milliseconds(250);
std::cout << "diff= " << d.count() << std::endl;
std::cout << "max_diff= " << max_diff.count() << std::endl;
assert( d < max_diff);
assert(test2 == 0);
}
++runs;
} catch(...) {
std::cout << "ERROR exception" << __LINE__ << std::endl;
assert(false);
}
}
int main()
{
try
{
boost::unique_lock<boost::mutex> lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
} catch(...) {
std::cout << "ERROR exception" << __LINE__ << std::endl;
BOOST_TEST(false);
}
test1 = 0;
test2 = 0;
try
{
boost::unique_lock<boost::mutex> lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
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,127 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#include <iostream>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
class Pred
{
int& i_;
public:
explicit Pred(int& i) :
i_(i)
{
}
bool operator()()
{
return i_ != 0;
}
};
boost::condition_variable cv;
boost::mutex mut;
int test1 = 0;
int test2 = 0;
int runs = 0;
typedef boost::chrono::system_clock Clock;
typedef boost::chrono::milliseconds milliseconds;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
try {
boost::unique_lock < boost::mutex > lk(mut);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
cv.wait_for(lk, milliseconds(250), Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < max_diff);
assert(test2 != 0);
}
else
{
assert(t1 - t0 - milliseconds(250) < max_diff);
assert(test2 == 0);
}
++runs;
} catch(...) {
std::cout << "ERROR exception" << __LINE__ << std::endl;
assert(false);
}
}
int main()
{
try
{
boost::unique_lock < boost::mutex > lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
test1 = 0;
test2 = 0;
try
{
boost::unique_lock < boost::mutex > lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
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,79 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// void wait(unique_lock<mutex>& lock);
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#include <iostream>
#if defined BOOST_THREAD_USES_CHRONO
boost::condition_variable cv;
boost::mutex mut;
int test1 = 0;
int test2 = 0;
int runs = 0;
void f()
{
try {
boost::unique_lock<boost::mutex> lk(mut);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
while (test2 == 0) {
cv.wait(lk);
}
assert(test2 != 0);
} catch(...) {
std::cout << "ERROR exception" << __LINE__ << std::endl;
assert(false);
}
}
int main()
{
try {
boost::unique_lock<boost::mutex>lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
{
cv.wait(lk);
}
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
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,128 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#include <cassert>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
struct Clock
{
typedef boost::chrono::milliseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef boost::chrono::time_point<Clock> time_point;
static const bool is_steady = true;
static time_point now()
{
using namespace boost::chrono;
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
}
};
boost::condition_variable cv;
boost::mutex mut;
int test1 = 0;
int test2 = 0;
int runs = 0;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
try {
boost::unique_lock < boost::mutex > lk(mut);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout) {}
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
assert(test2 != 0);
}
else
{
ns d = t1 - t0 - Clock::duration(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
assert(test2 == 0);
}
++runs;
} catch(...) {
assert(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
}
int main()
{
try
{
boost::unique_lock < boost::mutex > lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
test1 = 0;
test2 = 0;
try
{
boost::unique_lock < boost::mutex > lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
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,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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#include <iostream>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::milliseconds milliseconds;
typedef boost::chrono::nanoseconds nanoseconds;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
struct Clock
{
typedef boost::chrono::milliseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef boost::chrono::time_point<Clock> time_point;
static const bool is_steady = true;
static time_point now()
{
using namespace boost::chrono;
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
}
};
class Pred
{
int& i_;
public:
explicit Pred(int& i) :
i_(i)
{
}
bool operator()()
{
return i_ != 0;
}
};
boost::condition_variable cv;
boost::mutex mut;
int test1 = 0;
int test2 = 0;
int runs = 0;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
try {
boost::unique_lock<boost::mutex> lk(mut);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
bool r = cv.wait_until(lk, t, Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < max_diff);
assert(test2 != 0);
assert(r);
}
else
{
const nanoseconds d = t1 - t0 - milliseconds(250);
std::cout << "diff= " << d.count() << std::endl;
std::cout << "max_diff= " << max_diff.count() << std::endl;
assert(d < max_diff);
assert(test2 == 0);
assert(!r);
}
++runs;
} catch(...) {
std::cout << "ERROR exception" << __LINE__ << std::endl;
assert(false);
}
}
int main()
{
try
{
boost::unique_lock<boost::mutex> lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
test1 = 0;
test2 = 0;
try
{
boost::unique_lock<boost::mutex> lk(mut);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
} catch(...) {
BOOST_TEST(false);
std::cout << "ERROR exception" << __LINE__ << std::endl;
}
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,30 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any& operator=(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
void fail()
{
boost::condition_variable_any cv0;
boost::condition_variable_any cv1;
cv1 = cv0;
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/detail/lightweight_test.hpp>
void fail()
{
boost::condition_variable_any cv0;
boost::condition_variable_any cv1(cv0);
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
boost::condition_variable_any cv0;
return boost::report_errors();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/locks.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::condition_variable_any* cv;
boost::timed_mutex m;
typedef boost::unique_lock<boost::timed_mutex> Lock;
bool f_ready = false;
bool g_ready = false;
void f()
{
Lock lk(m);
f_ready = true;
cv->notify_one();
cv->wait(lk);
delete cv;
}
void g()
{
Lock lk(m);
g_ready = true;
cv->notify_one();
while (!f_ready)
{
cv->wait(lk);
}
cv->notify_one();
}
int main()
{
cv = new boost::condition_variable_any;
boost::thread th2(g);
Lock lk(m);
while (!g_ready)
{
cv->wait(lk);
}
lk.unlock();
boost::thread th1(f);
th1.join();
th2.join();
return boost::report_errors();
}

View File

@@ -0,0 +1,241 @@
//===----------------------------------------------------------------------===//
//
// 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) 2017 Austin J. Beer
//
// 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/condition_variable>
// class condition_variable;
// condition_variable(const condition_variable&) = delete;
#include <iostream>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
// Summary of each test:
// 1. Start the test thread and wait for it to start up.
// The test thread waits for the flag to be set using a large timeout.
// 2. The main thread takes the lock and then sleeps for a long time while holding
// the lock before setting the flag and calling notify_one(). If the wait
// function being tested is polling pthread_cond_timedwait() internally, any
// notifications sent after pthread_cond_timedwait() times out but before it can
// reacquire the lock may be "lost". pthread_cond_timedwait() will report that
// it timed out and the wait function may incorrectly assume that no
// notification was received. This test ensures that that doesn't happen.
// 3. Measure how it takes the test thread to return. If it received the
// notification, it will return fairly quickly. If it missed the notification,
// the test thread won't return until the wait function being tested times out.
//------------------------------------------------------------------------------
boost::condition_variable_any cv;
boost::mutex mut;
bool flag;
bool waiting;
bool flagIsSet()
{
return flag;
}
bool threadIsWaiting()
{
return waiting;
}
//------------------------------------------------------------------------------
#ifdef BOOST_THREAD_USES_DATETIME
boost::posix_time::milliseconds posix_wait_time(1000);
template <typename F>
void test_posix_wait_function(F f)
{
flag = false;
waiting = false;
boost::thread t(f);
while (!threadIsWaiting())
{
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
boost::unique_lock<boost::mutex> lk(mut);
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
boost::posix_time::ptime t0 = boost::posix_time::microsec_clock::universal_time();
flag = true;
cv.notify_one();
lk.unlock();
t.join();
boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::universal_time();
BOOST_TEST(t1 - t0 < boost::posix_time::milliseconds(250));
}
//------------------------------------------------------------------------------
void timed_wait_absolute_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.timed_wait(lk, boost::posix_time::microsec_clock::universal_time() + posix_wait_time);
}
}
void timed_wait_absolute_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.timed_wait(lk, boost::posix_time::microsec_clock::universal_time() + posix_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void timed_wait_relative_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.timed_wait(lk, posix_wait_time);
}
}
void timed_wait_relative_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.timed_wait(lk, posix_wait_time, flagIsSet);
}
#else
#error "Test not applicable: BOOST_THREAD_USES_DATETIME not defined for this platform as not supported"
#endif
//------------------------------------------------------------------------------
#ifdef BOOST_THREAD_USES_CHRONO
boost::chrono::milliseconds chrono_wait_time(1000);
template <typename F>
void test_chrono_wait_function(F f)
{
flag = false;
waiting = false;
boost::thread t(f);
while (!threadIsWaiting())
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
}
boost::unique_lock<boost::mutex> lk(mut);
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
boost::chrono::steady_clock::time_point t0 = boost::chrono::steady_clock::now();
flag = true;
cv.notify_one();
lk.unlock();
t.join();
boost::chrono::steady_clock::time_point t1 = boost::chrono::steady_clock::now();
BOOST_TEST(t1 - t0 < boost::chrono::milliseconds(250));
}
//------------------------------------------------------------------------------
void wait_until_system_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_until(lk, boost::chrono::system_clock::now() + chrono_wait_time);
}
}
void wait_until_system_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_until(lk, boost::chrono::system_clock::now() + chrono_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void wait_until_steady_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_until(lk, boost::chrono::steady_clock::now() + chrono_wait_time);
}
}
void wait_until_steady_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_until(lk, boost::chrono::steady_clock::now() + chrono_wait_time, flagIsSet);
}
//------------------------------------------------------------------------------
void wait_for_without_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
while (!flagIsSet())
{
cv.wait_for(lk, chrono_wait_time);
}
}
void wait_for_with_pred()
{
boost::unique_lock<boost::mutex> lk(mut);
waiting = true;
cv.wait_for(lk, chrono_wait_time, flagIsSet);
}
#else
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
#endif
//------------------------------------------------------------------------------
int main()
{
#ifdef BOOST_THREAD_USES_DATETIME
test_posix_wait_function(timed_wait_absolute_without_pred);
test_posix_wait_function(timed_wait_absolute_with_pred);
test_posix_wait_function(timed_wait_relative_without_pred);
test_posix_wait_function(timed_wait_relative_with_pred);
#endif
#ifdef BOOST_THREAD_USES_CHRONO
test_chrono_wait_function(wait_until_system_without_pred);
test_chrono_wait_function(wait_until_system_with_pred);
test_chrono_wait_function(wait_until_steady_without_pred);
test_chrono_wait_function(wait_until_steady_with_pred);
test_chrono_wait_function(wait_for_without_pred);
test_chrono_wait_function(wait_for_with_pred);
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,104 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
boost::condition_variable_any cv;
typedef boost::timed_mutex L0;
typedef boost::unique_lock<L0> L1;
L0 m0;
int test1 = 0;
int test2 = 0;
int runs = 0;
typedef boost::chrono::system_clock Clock;
typedef boost::chrono::milliseconds milliseconds;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + milliseconds(250);
while (test2 == 0 && cv.wait_for(lk, t - Clock::now()) == boost::cv_status::no_timeout) {}
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 != 0);
}
else
{
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 == 0);
}
++runs;
}
int main()
{
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
}
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,118 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
class Pred
{
int& i_;
public:
explicit Pred(int& i) :
i_(i)
{
}
bool operator()()
{
return i_ != 0;
}
};
boost::condition_variable_any cv;
typedef boost::timed_mutex L0;
typedef boost::unique_lock<L0> L1;
L0 m0;
int test1 = 0;
int test2 = 0;
int runs = 0;
typedef boost::chrono::system_clock Clock;
typedef boost::chrono::milliseconds milliseconds;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
cv.wait_for(lk, milliseconds(250), Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0 ;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 != 0);
}
else
{
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 == 0);
}
++runs;
}
int main()
{
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
}
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,115 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
struct Clock
{
typedef boost::chrono::milliseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef boost::chrono::time_point<Clock> time_point;
static const bool is_steady = true;
static time_point now()
{
using namespace boost::chrono;
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
}
};
boost::condition_variable_any cv;
typedef boost::timed_mutex L0;
typedef boost::unique_lock<L0> L1;
L0 m0;
int test1 = 0;
int test2 = 0;
int runs = 0;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout) {}
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 != 0);
}
else
{
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 == 0);
}
++runs;
}
int main()
{
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
}
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,134 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable_any>
// class condition_variable_any;
// condition_variable_any(const condition_variable_any&) = delete;
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
struct Clock
{
typedef boost::chrono::milliseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef boost::chrono::time_point<Clock> time_point;
static const bool is_steady = true;
static time_point now()
{
using namespace boost::chrono;
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
}
};
class Pred
{
int& i_;
public:
explicit Pred(int& i) :
i_(i)
{
}
bool operator()()
{
return i_ != 0;
}
};
boost::condition_variable_any cv;
typedef boost::timed_mutex L0;
typedef boost::unique_lock<L0> L1;
L0 m0;
int test1 = 0;
int test2 = 0;
int runs = 0;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
L1 lk(m0);
BOOST_TEST(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
bool r = cv.wait_until(lk, t, Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 != 0);
BOOST_TEST(r);
}
else
{
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(test2 == 0);
BOOST_TEST(!r);
}
++runs;
}
int main()
{
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
boost::thread t(f);
BOOST_TEST(test1 == 0);
while (test1 == 0)
cv.wait(lk);
BOOST_TEST(test1 != 0);
lk.unlock();
t.join();
}
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,60 @@
//===----------------------------------------------------------------------===//
//
// 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/thread.hpp>
// class thread
// static unsigned hardware_concurrency();
#include <boost/thread/condition_variable.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
BOOST_TEST(boost::cv_status::no_timeout != boost::cv_status::timeout);
}
{
boost::cv_status st = boost::cv_status::no_timeout;
BOOST_TEST(st == boost::cv_status::no_timeout);
BOOST_TEST(boost::cv_status::no_timeout==st);
BOOST_TEST(st != boost::cv_status::timeout);
BOOST_TEST(boost::cv_status::timeout!=st);
}
{
boost::cv_status st = boost::cv_status::timeout;
BOOST_TEST(st == boost::cv_status::timeout);
BOOST_TEST(boost::cv_status::timeout==st);
BOOST_TEST(st != boost::cv_status::no_timeout);
BOOST_TEST(boost::cv_status::no_timeout!=st);
}
{
boost::cv_status st;
st = boost::cv_status::no_timeout;
BOOST_TEST(st == boost::cv_status::no_timeout);
BOOST_TEST(boost::cv_status::no_timeout==st);
BOOST_TEST(st != boost::cv_status::timeout);
BOOST_TEST(boost::cv_status::timeout!=st);
}
{
boost::cv_status st;
st = boost::cv_status::timeout;
BOOST_TEST(st == boost::cv_status::timeout);
BOOST_TEST(boost::cv_status::timeout==st);
BOOST_TEST(st != boost::cv_status::no_timeout);
BOOST_TEST(boost::cv_status::no_timeout!=st);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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/condition_variable.hpp>
// void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
#define BOOST_THREAD_USES_MOVE
#define BOOST_THREAD_VESRION 3
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/thread.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::condition_variable cv;
boost::mutex mut;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::high_resolution_clock Clock;
void func()
{
boost::unique_lock < boost::mutex > lk(mut);
boost::notify_all_at_thread_exit(cv, boost::move(lk));
boost::this_thread::sleep_for(ms(300));
}
int main()
{
boost::unique_lock < boost::mutex > lk(mut);
boost::thread(func).detach();
Clock::time_point t0 = Clock::now();
cv.wait(lk);
Clock::time_point t1 = Clock::now();
BOOST_TEST(t1 - t0 > ms(250));
return boost::report_errors();
}

View File

@@ -0,0 +1,250 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class Executor, class F, class... Args>
// future<typename result_of<F(Args...)>::type>
// async(Executor& ex, F&& f, Args&&... args);
#define BOOST_THREAD_VERSION 5
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <iostream>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/detail/memory.hpp>
#include <boost/thread/csbl/memory/unique_ptr.hpp>
#include <memory>
#include <boost/detail/lightweight_test.hpp>
#include <boost/thread/executors/basic_thread_pool.hpp>
#include <boost/thread/executor.hpp>
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::milliseconds ms;
class A
{
long data_;
public:
typedef long result_type;
explicit A(long i) :
data_(i)
{
}
long doit() const
{
boost::this_thread::sleep_for(ms(200));
return data_;
}
long operator()() const
{
boost::this_thread::sleep_for(ms(200));
return data_;
}
};
class MoveOnly
{
public:
typedef int result_type;
int value;
BOOST_THREAD_MOVABLE_ONLY(MoveOnly)
MoveOnly()
{
value = 0;
}
MoveOnly( BOOST_THREAD_RV_REF(MoveOnly))
{
value = 1;
}
MoveOnly& operator=(BOOST_THREAD_RV_REF(MoveOnly))
{
value = 2;
return *this;
}
int operator()()
{
boost::this_thread::sleep_for(ms(200));
return 3;
}
template <typename OS>
friend OS& operator<<(OS& os, MoveOnly const& v)
{
os << v.value;
return os;
}
};
namespace boost
{
BOOST_THREAD_DCL_MOVABLE (MoveOnly)
}
int f0()
{
boost::this_thread::sleep_for(ms(200));
return 3;
}
int i = 0;
int& f1()
{
boost::this_thread::sleep_for(ms(200));
return i;
}
void f2()
{
boost::this_thread::sleep_for(ms(200));
}
boost::csbl::unique_ptr<int> f3_0()
{
boost::this_thread::sleep_for(ms(200));
boost::csbl::unique_ptr<int> r( (new int(3)));
return boost::move(r);
}
MoveOnly f3_1()
{
boost::this_thread::sleep_for(ms(200));
MoveOnly r;
return boost::move(r);
}
boost::csbl::unique_ptr<int> f3(int i)
{
boost::this_thread::sleep_for(ms(200));
return boost::csbl::unique_ptr<int>(new int(i));
}
boost::csbl::unique_ptr<int> f4(
BOOST_THREAD_RV_REF_BEG boost::csbl::unique_ptr<int> BOOST_THREAD_RV_REF_END p
)
{
boost::this_thread::sleep_for(ms(200));
return boost::move(p);
}
struct check_timer {
boost::chrono::nanoseconds delay;
Clock::time_point start;
check_timer(boost::chrono::nanoseconds delay)
: delay(delay)
, start(Clock::now())
{
}
~check_timer() {
Clock::time_point now = Clock::now();
BOOST_TEST(now - start < delay);
std::cout << __FILE__ << "[" << __LINE__ << "] " << (now - start).count() << std::endl;
}
};
int main()
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
{
try
{
boost::executor_adaptor<boost::basic_thread_pool> ex(1);
boost::future<int> f = boost::async(ex, &f0);
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#endif
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) && defined BOOST_THREAD_PROVIDES_EXECUTORS
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try
{
boost::executor_adaptor<boost::basic_thread_pool> ex(1);
boost::future<long> f = boost::async(ex, A(3));
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#endif
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) && defined BOOST_THREAD_PROVIDES_EXECUTORS
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try
{
boost::executor_adaptor<boost::basic_thread_pool> ex(1);
MoveOnly mo;
boost::future<int> f = boost::async(ex, boost::move(mo));
//boost::future<int> f = boost::async(ex, MoveOnly());
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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

@@ -0,0 +1,903 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class F, class... Args>
// future<typename result_of<F(Args...)>::type>
// async(F&& f, Args&&... args);
// template <class F, class... Args>
// future<typename result_of<F(Args...)>::type>
// async(launch policy, F&& f, Args&&... args);
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <iostream>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/detail/memory.hpp>
#include <boost/thread/csbl/memory/unique_ptr.hpp>
#include <memory>
#include <boost/detail/lightweight_test.hpp>
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::milliseconds ms;
class A
{
long data_;
public:
typedef long result_type;
explicit A(long i) :
data_(i)
{
}
long doit() const
{
boost::this_thread::sleep_for(ms(200));
return data_;
}
long operator()() const
{
boost::this_thread::sleep_for(ms(200));
return data_;
}
};
class MoveOnly
{
public:
typedef int result_type;
int value;
BOOST_THREAD_MOVABLE_ONLY(MoveOnly)
MoveOnly()
{
value = 0;
}
MoveOnly( BOOST_THREAD_RV_REF(MoveOnly))
{
value = 1;
}
MoveOnly& operator=(BOOST_THREAD_RV_REF(MoveOnly))
{
value = 2;
return *this;
}
int operator()() const
{
boost::this_thread::sleep_for(ms(200));
return 3;
}
template <typename OS>
friend OS& operator<<(OS& os, MoveOnly const& v)
{
os << v.value;
return os;
}
};
namespace boost
{
BOOST_THREAD_DCL_MOVABLE (MoveOnly)
}
int f0()
{
boost::this_thread::sleep_for(ms(200));
return 3;
}
int i = 0;
int& f1()
{
boost::this_thread::sleep_for(ms(200));
return i;
}
void f2()
{
boost::this_thread::sleep_for(ms(200));
}
boost::csbl::unique_ptr<int> f3_0()
{
boost::this_thread::sleep_for(ms(200));
boost::csbl::unique_ptr<int> r( (new int(3)));
return boost::move(r);
}
MoveOnly f3_1()
{
boost::this_thread::sleep_for(ms(200));
MoveOnly r;
return boost::move(r);
}
boost::csbl::unique_ptr<int> f3(int i)
{
boost::this_thread::sleep_for(ms(200));
return boost::csbl::unique_ptr<int>(new int(i));
}
boost::csbl::unique_ptr<int> f4(
BOOST_THREAD_RV_REF_BEG boost::csbl::unique_ptr<int> BOOST_THREAD_RV_REF_END p
)
{
boost::this_thread::sleep_for(ms(200));
return boost::move(p);
}
struct check_timer {
boost::chrono::nanoseconds delay;
Clock::time_point start;
check_timer(boost::chrono::nanoseconds delay)
: delay(delay)
, start(Clock::now())
{
}
~check_timer() {
Clock::time_point now = Clock::now();
BOOST_TEST(now - start < delay);
std::cout << __FILE__ << "[" << __LINE__ << "] " << (now - start).count() << std::endl;
}
};
int main()
{
{
try {
boost::async(f0);
} catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
{
try {
boost::async(boost::launch::async, f0);
} catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try {
boost::async(boost::launch::deferred, f0);
} 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(f0);
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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::shared_future<int> f = boost::async(f0).share();
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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<long> f = boost::async(boost::launch::async, A(3));
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try
{
boost::future<long> f = boost::async(boost::launch::deferred, A(3));
//boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#endif
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try
{
A a(3);
boost::future<long> f = boost::async(boost::launch::async, &A::doit, &a);
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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
{
A a(3);
boost::future<long> f = boost::async(boost::launch::deferred, &A::doit, &a);
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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(boost::launch::async, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#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, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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(boost::launch::any, f0);
boost::this_thread::sleep_for(ms(300));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#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));
int res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res == 3);
}
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));
int* res;
{
check_timer timer(ms(500));
res = &f.get();
}
BOOST_TEST(res == &i);
}
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));
int* res;
{
check_timer timer(ms(500));
res = &f.get();
}
BOOST_TEST(res == &i);
}
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));
int* res;
{
check_timer timer(ms(500));
res = &f.get();
}
BOOST_TEST(res == &i);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#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, f1);
//boost::this_thread::sleep_for(ms(300));
int* res;
{
check_timer timer(ms(500));
res = &f.get();
}
BOOST_TEST(res == &i);
}
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);
boost::this_thread::sleep_for(ms(300));
{
check_timer timer(ms(500));
f.get();
}
}
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));
{
check_timer timer(ms(500));
f.get();
}
}
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));
{
check_timer timer(ms(500));
f.get();
}
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#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));
{
check_timer timer(ms(500));
f.get();
}
}
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<MoveOnly> f = boost::async(&f3_1);
boost::this_thread::sleep_for(ms(300));
MoveOnly res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST_EQ(res.value, 2);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
{
try
{
boost::future<MoveOnly> f = boost::async(boost::launch::deferred, &f3_1);
//boost::this_thread::sleep_for(ms(300));
MoveOnly res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST_EQ(res.value, 2);
}
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<MoveOnly> f;
f = boost::async(&f3_1);
boost::this_thread::sleep_for(ms(300));
MoveOnly res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(res.value == 2);
}
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<boost::csbl::unique_ptr<int> > f = boost::async(&f3_0);
boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try
{
boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f3, 3);
boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
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<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f3, 3);
//boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
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<boost::csbl::unique_ptr<int> > f = boost::async(&f3, 3);
boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
catch (std::exception& ex)
{
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
BOOST_TEST(false && "exception thrown");
}
catch (...)
{
BOOST_TEST(false && "exception thrown");
}
}
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
{
try
{
boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f4, boost::csbl::unique_ptr<int>(new int(3)));
boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
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<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f4, boost::csbl::unique_ptr<int>(new int(3)));
//boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
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<boost::csbl::unique_ptr<int> > f = boost::async(&f4, boost::csbl::unique_ptr<int>(new int(3)));
boost::this_thread::sleep_for(ms(300));
boost::csbl::unique_ptr<int> res;
{
check_timer timer(ms(500));
res = f.get();
}
BOOST_TEST(*res == 3);
}
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

@@ -0,0 +1,153 @@
// Copyright (C) 2012-2013 Vicente Botet
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class future<R>
// template<typename F>
// auto then(F&& func) -> future<decltype(func(*this))>;
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
int p1()
{
BOOST_THREAD_LOG << "p1 < " << BOOST_THREAD_END_LOG;
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p1 >" << BOOST_THREAD_END_LOG;
return 1;
}
int p2(boost::future<int> f)
{
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
return 2 * i;
}
void p3(boost::future<int> f)
{
BOOST_THREAD_LOG << "p3 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p3 <" << &f << " " <<i << BOOST_THREAD_END_LOG;
return;
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
try
{
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
BOOST_TEST(f1.valid());
{
boost::future<int> f2 = f1.then(&p2);
BOOST_TEST(f2.valid());
}
BOOST_TEST(! f1.valid());
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
BOOST_TEST(f1.valid());
boost::future<int> f2 = f1.then(&p2);
BOOST_TEST(f2.valid());
BOOST_TEST(! f1.valid());
try
{
BOOST_TEST(f2.get()==2);
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
BOOST_TEST(f1.valid());
boost::future<void> f2 = f1.then(&p3);
BOOST_TEST(f2.valid());
try
{
f2.wait();
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f2 = boost::async(boost::launch::deferred, p1).then(&p2);
BOOST_TEST(f2.get()==2);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::deferred, p1);
boost::future<int> f21 = f1.then(&p2);
boost::future<int> f2= f21.then(&p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::deferred, p1);
boost::future<int> f2= f1.then(&p2).then(&p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f2 = boost::async(boost::launch::deferred, p1).then(&p2).then(&p2);
BOOST_TEST(f2.get()==4);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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 future<R>
// future& operator=(const future&) = delete;
#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::future<T> f0 = p.get_future();
boost::future<T> f;
f = f0;
}
return boost::report_errors();
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// 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 future<R>
// future(const future&) = delete;
#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::future<T> f0 = p.get_future();
boost::future<T> f = f0;
}
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 future<R>
// future();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::future<int> f;
BOOST_TEST(!f.valid());
}
{
boost::future<int&> f;
BOOST_TEST(!f.valid());
}
{
boost::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 future<R>
// ~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::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::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::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::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::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::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,184 @@
// Copyright (C) 2013 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>
// R future::get_or(R&&);
// R& future<R&>::get_or(R&);
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/core/ref.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
template <typename T>
struct wrap
{
wrap(T const& v) : value(v){}
T value;
};
template <typename T>
boost::exception_ptr make_exception_ptr(T v) {
return boost::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(::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(::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(::make_exception_ptr(4));
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(func1, boost::move(p)).detach();
#else
p.set_value(3);
#endif
BOOST_TEST(f.valid());
BOOST_TEST(f.get_or(4) == 3);
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::promise<T> p;
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
boost::future<T> f = p.get_future();
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
#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(::make_exception_ptr(3));
#endif
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
try
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(f.get_or(4) == 4);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
catch (...)
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(!f.valid());
#endif
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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());
int k=4;
BOOST_TEST(f.get_or(boost::ref(k)) == 5);
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
int j=4;
BOOST_TEST(f.get_or(boost::ref(j)) == 4);
}
catch (...)
{
BOOST_TEST(false);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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,265 @@
//===----------------------------------------------------------------------===//
//
// 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 future<R>
// const R& future::get();
// R& future<R&>::get();
// void future<void>::get();
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
template <typename T>
struct wrap
{
wrap(T const& v) : value(v){}
T value;
};
template <typename T>
boost::exception_ptr make_exception_ptr(T v) {
return boost::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(::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(::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(::make_exception_ptr(4));
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(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_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::promise<T> p;
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
boost::future<T> f = p.get_future();
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
#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(::make_exception_ptr(3));
#endif
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
try
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(f.get() == 3);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
catch (::wrap<int> const& i)
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(i.value == 3);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
catch (...)
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_TEST(!f.valid());
#endif
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (::wrap<double> const& i)
{
BOOST_TEST(i.value == 3.5);
}
#ifdef BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET
BOOST_TEST(!f.valid());
#endif
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
boost::exception_ptr ptr = f.get_exception_ptr();
}
catch (...)
{
BOOST_TEST(false);
}
BOOST_TEST(f.valid());
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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(::make_exception_ptr(4));
#endif
try
{
BOOST_TEST(f.valid());
f.get();
BOOST_TEST(false);
}
catch (::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
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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 future<R>
// future& operator=(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::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::future<T> f0;
boost::future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::future<T> f0;
boost::future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f;
f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::future<T> f0;
boost::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 future<R>
// future(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::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::future<T> f0;
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::future<T> f0;
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::future<T> f0;
boost::future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// 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 future<R>
// shared_future<R> share() &&;
#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::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::future<T> f0;
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::future<T> f0;
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::future<T> f0 = BOOST_THREAD_MAKE_RV_REF(p.get_future());
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::future<T> f0;
boost::shared_future<T> sf = f0.share();
boost::shared_future<T> f = sf;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,137 @@
// Copyright (C) 2012-2013 Vicente Botet
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class future<R>
// template<typename F>
// auto then(F&& func) -> future<decltype(func(*this))>;
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
int p1()
{
BOOST_THREAD_LOG << "p1 < " << BOOST_THREAD_END_LOG;
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p1 >" << BOOST_THREAD_END_LOG;
return 1;
}
int p2(boost::future<int> f)
{
assert(f.is_ready());
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
return 2 * i;
}
void p3(boost::future<int> f)
{
assert(f.is_ready());
BOOST_THREAD_LOG << "p3 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p3 <" << &f << " " <<i << BOOST_THREAD_END_LOG;
return;
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<int> f2 = f1.then(boost::launch::deferred, &p2);
BOOST_TEST(f2.valid());
BOOST_TEST(! f1.valid());
try
{
BOOST_TEST(f2.get()==2);
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<void> f2 = f1.then(boost::launch::deferred, &p3);
BOOST_TEST(f2.valid());
try
{
f2.wait();
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f2 = boost::async(p1).then(boost::launch::deferred, &p2);
BOOST_TEST(f2.get()==2);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f21 = f1.then(boost::launch::deferred, &p2);
boost::future<int> f2= f21.then(boost::launch::deferred, &p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f2= f1.then(boost::launch::deferred, &p2).then(boost::launch::deferred, &p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f2 = boost::async(p1).then(boost::launch::deferred, &p2).then(boost::launch::deferred, &p2);
BOOST_TEST(f2.get()==4);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,152 @@
// Copyright (C) 2014 Vicente Botet
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class future<R>
// template<typename F>
// auto then(F&& func) -> future<decltype(func(*this))>;
#define BOOST_THREAD_VERSION 5
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/thread/executors/basic_thread_pool.hpp>
#include <boost/thread/executor.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cassert>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
int p1()
{
BOOST_THREAD_LOG << "p1 < " << BOOST_THREAD_END_LOG;
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p1 >" << BOOST_THREAD_END_LOG;
return 1;
}
int p2(boost::future<int> f)
{
assert(f.is_ready());
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
return 2 * i;
}
void p3(boost::future<int> f)
{
assert(f.is_ready());
BOOST_THREAD_LOG << "p3 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p3 <" << &f << " " <<i << BOOST_THREAD_END_LOG;
return;
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<int> f2 = f1.then(ex, &p2);
BOOST_TEST(f2.valid());
BOOST_TEST(! f1.valid());
try
{
BOOST_TEST(f2.get()==2);
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<void> f2 = f1.then(ex, &p3);
BOOST_TEST(f2.valid());
try
{
f2.wait();
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f2 = boost::async(p1).then(ex, &p2);
BOOST_TEST(f2.get()==2);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f1 = boost::async(p1);
boost::future<int> f21 = f1.then(ex, &p2);
boost::future<int> f2= f21.then(ex, &p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f1 = boost::async(p1);
boost::future<int> f21 = f1.then(ex, &p2);
boost::future<int> f2= f21.then(&p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f1 = boost::async(p1);
boost::future<int> f2= f1.then(&p2).then(ex, &p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::basic_thread_pool ex(1);
boost::future<int> f2 = boost::async(p1).then(ex, &p2).then(ex, &p2);
BOOST_TEST(f2.get()==4);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,133 @@
// Copyright (C) 2012-2013 Vicente Botet
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class future<R>
// template<typename F>
// auto then(F&& func) -> future<decltype(func(*this))>;
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
int p1()
{
BOOST_THREAD_LOG << "p1 < " << BOOST_THREAD_END_LOG;
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p1 >" << BOOST_THREAD_END_LOG;
return 1;
}
int p2(boost::future<int> f)
{
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p2 <" << &f << BOOST_THREAD_END_LOG;
return 2 * i;
}
void p3(boost::future<int> f)
{
BOOST_THREAD_LOG << "p3 <" << &f << BOOST_THREAD_END_LOG;
BOOST_TEST(f.valid());
int i = f.get();
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
BOOST_THREAD_LOG << "p3 <" << &f << " " <<i << BOOST_THREAD_END_LOG;
return;
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<int> f2 = f1.then(&p2);
BOOST_TEST(f2.valid());
BOOST_TEST(! f1.valid());
try
{
BOOST_TEST(f2.get()==2);
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<void> f2 = f1.then(&p3);
BOOST_TEST(f2.valid());
try
{
f2.wait();
}
catch (std::exception& ex)
{
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
catch (...)
{
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
BOOST_TEST(false);
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f2 = boost::async(p1).then(&p2);
BOOST_TEST(f2.get()==2);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f21 = f1.then(&p2);
boost::future<int> f2= f21.then(&p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
boost::future<int> f1 = boost::async(p1);
boost::future<int> f2= f1.then(&p2).then(&p2);
BOOST_TEST(f2.get()==4);
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
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

@@ -0,0 +1,158 @@
//===----------------------------------------------------------------------===//
//
// 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) 2013 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 <class Rep, class Period>
// future_status
// wait_for(const chrono::duration<Rep, Period>& rel_time) const;
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include "../../../timming.hpp"
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/chrono/chrono_io.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
namespace boost
{
template <typename OStream>
OStream& operator<<(OStream& os , boost::future_status st )
{
os << underlying_cast<int>(st) << " ";
return os;
}
}
void func1(boost::promise<int> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value(3);
}
int j = 0;
void func3(boost::promise<int&> p)
{
boost::this_thread::sleep_for(ms(500));
j = 5;
p.set_value(j);
}
void func5(boost::promise<void> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value();
}
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
typedef boost::chrono::high_resolution_clock Clock;
{
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(func1, boost::move(p)).detach();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_for(ms(250)) , boost::future_status::timeout);
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func1(boost::move(p));
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_for(ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
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();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_for(ms(250)) , boost::future_status::timeout);
BOOST_TEST(f.valid());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func3(boost::move(p));
#endif
BOOST_TEST_EQ(f.wait_for(ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
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();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_for(ms(250)) , boost::future_status::timeout);
BOOST_TEST(f.valid());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func5(boost::move(p));
#endif
BOOST_TEST_EQ(f.wait_for(ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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,139 @@
//===----------------------------------------------------------------------===//
//
// 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) 2013 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 <class Rep, class Period>
// void wait() const;
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/chrono/chrono_io.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_USES_CHRONO
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
typedef boost::chrono::milliseconds ms;
namespace boost
{
template <typename OStream>
OStream& operator<<(OStream& os , boost::future_status st )
{
os << underlying_cast<int>(st) << " ";
return os;
}
}
void func1(boost::promise<int> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value(3);
}
int j = 0;
void func3(boost::promise<int&> p)
{
boost::this_thread::sleep_for(ms(500));
j = 5;
p.set_value(j);
}
void func5(boost::promise<void> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value();
}
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
typedef boost::chrono::high_resolution_clock Clock;
{
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(func1, boost::move(p)).detach();
#else
func1(boost::move(p));
#endif
BOOST_TEST(f.valid());
f.wait();
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
BOOST_TEST(t1 - t0 < ms(50));
}
{
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
func3(boost::move(p));
#endif
BOOST_TEST(f.valid());
f.wait();
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
BOOST_TEST(t1 - t0 < ms(50));
}
{
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
func5(boost::move(p));
#endif
BOOST_TEST(f.valid());
f.wait();
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
BOOST_TEST(t1 - t0 < ms(50));
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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,159 @@
//===----------------------------------------------------------------------===//
//
// 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) 2013 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 <class Rep, class Period>
// future_status
// wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID
#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <boost/chrono/chrono_io.hpp>
#include <boost/detail/lightweight_test.hpp>
#include "../../../timming.hpp"
#if defined BOOST_THREAD_USES_CHRONO
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
namespace boost
{
template <typename OStream>
OStream& operator<<(OStream& os , boost::future_status st )
{
os << underlying_cast<int>(st) << " ";
return os;
}
}
void func1(boost::promise<int> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value(3);
}
int j = 0;
void func3(boost::promise<int&> p)
{
boost::this_thread::sleep_for(ms(500));
j = 5;
p.set_value(j);
}
void func5(boost::promise<void> p)
{
boost::this_thread::sleep_for(ms(500));
p.set_value();
}
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
int main()
{
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
{
typedef boost::chrono::high_resolution_clock Clock;
{
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(func1, boost::move(p)).detach();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func1(boost::move(p));
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
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();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
BOOST_TEST(f.valid());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func3(boost::move(p));
#endif
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
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();
#endif
BOOST_TEST(f.valid());
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(250)) , boost::future_status::timeout);
BOOST_TEST(f.valid());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
func5(boost::move(p));
#endif
BOOST_TEST_EQ(f.wait_until(Clock::now() + ms(750)) , boost::future_status::ready);
BOOST_TEST(f.valid());
Clock::time_point t0 = Clock::now();
f.wait();
Clock::time_point t1 = Clock::now();
BOOST_TEST(f.valid());
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
}
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
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,157 @@
//===----------------------------------------------------------------------===//
//
// 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,2014 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>
// future<void> make_ready_future();
// template <class T>
// future<decay_t<T>> make_ready_future(T&&);
// template <class T>
// future<T> make_ready_future(remove_reference_t<T>&);
// template <class T>
// future<T> make_ready_future(remove_reference_t<T>&&);
// template <class T, class ...Args>
// future<T> make_ready_future(Args&& ... args);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
struct A
{
A() :
value(0)
{
}
A(int i) :
value(i)
{
}
A(int i, int j) :
value(i+j)
{
}
int value;
};
A make(int i) {
return A(i);
}
A make(int i, int j) {
return A(i, j);
}
struct movable2
{
int value_;
BOOST_THREAD_MOVABLE_ONLY(movable2)
movable2() : value_(1){}
movable2(int i) : value_(i){}
movable2(int i, int j) : value_(i+j){}
//Move constructor and assignment
movable2(BOOST_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; }
movable2 & operator=(BOOST_THREAD_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; return *this; }
bool moved() const //Observer
{ return !value_; }
int value() const //Observer
{ return value_; }
};
movable2 move_return_function2(int i) {
return movable2(i);
}
int main()
{
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_STATIC_ASSERT((boost::is_copy_constructible<movable2>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<movable2>::value == true));
BOOST_STATIC_ASSERT((boost::is_copy_constructible<A>::value == true));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<A>::value == false));
#endif
{
boost::future<void> f = boost::make_ready_future();
f.wait();
}
{
typedef A T;
T i;
boost::future<T> f = boost::make_ready_future(i);
BOOST_TEST(f.get().value==0);
}
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>();
BOOST_TEST(f.get().value==0);
}
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>(1);
BOOST_TEST(f.get().value==1);
}
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>(1,2);
BOOST_TEST(f.get().value==3);
}
{
typedef A T;
T i;
boost::future<T&> f = boost::make_ready_future<T&>(i);
BOOST_TEST(f.get().value==0);
}
#endif
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// sync/futures/make_ready_future_pass.cpp:125:65: erreur: conversion from <20>boost::future<boost::rv<movable2> ><3E> to non-scalar type <20>boost::future<movable2><3E> requested
{
typedef movable2 T;
T i;
boost::future<T> f = boost::make_ready_future(boost::move(i));
BOOST_TEST_EQ(f.get().value(),1);
}
#endif
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>();
BOOST_TEST(f.get().value()==1);
}
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>(1);
BOOST_TEST(f.get().value()==1);
}
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>(1,2);
BOOST_TEST(f.get().value()==3);
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,181 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class F, class Allocator>
// explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
#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"
double fct()
{
return 5.0;
}
long lfct()
{
return 5;
}
class A
{
long data_;
public:
BOOST_THREAD_COPYABLE_AND_MOVABLE(A)
static int n_moves;
static int n_copies;
static int n_instances;
static int n_destroy;
explicit A(long i) : data_(i)
{
++n_instances;
}
A(BOOST_THREAD_RV_REF(A) a) : data_(BOOST_THREAD_RV(a).data_)
{
++n_instances;
++n_moves; BOOST_THREAD_RV(a).data_ = -1;
}
A& operator=(BOOST_THREAD_RV_REF(A) a)
{
data_ = BOOST_THREAD_RV(a).data_;
BOOST_THREAD_RV(a).data_ = -1;
++n_moves;
return *this;
}
A(const A& a) : data_(a.data_)
{
++n_instances;
++n_copies;
}
A& operator=(BOOST_THREAD_COPY_ASSIGN_REF(A) a)
{
data_ = a.data_;
++n_copies;
return *this;
}
~A()
{
--n_instances;
++n_destroy;
}
long operator()() const
{ return data_;}
long operator()(long i, long j) const
{ return data_ + i + j;}
};
int A::n_moves = 0;
int A::n_copies = 0;
int A::n_instances = 0;
int A::n_destroy = 0;
int main()
{
{
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());
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_instances == 0);
BOOST_TEST(A::n_destroy > 0);
BOOST_TEST(test_alloc_base::count == 0);
A::n_copies = 0;
A::n_moves = 0;
{
A a(5);
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());
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(test_alloc_base::count == 0);
A::n_copies = 0;
A::n_moves = 0;
{
const A a(5);
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());
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(test_alloc_base::count == 0);
{
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());
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<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::allocator_arg,
test_allocator<A>(), &lfct);
BOOST_TEST(test_alloc_base::count > 0);
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);
}
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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& operator=(packaged_task&) = delete;
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p = p0;
}
return boost::report_errors();
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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&) = delete;
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p0(A(5));
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(p0);
}
return boost::report_errors();
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// 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();
#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>
#include <string>
int main()
{
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
BOOST_TEST(!p.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,108 @@
//===----------------------------------------------------------------------===//
//
// 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();
//#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_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
void func(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> )
{
}
void func2(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
#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<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
{
f.get();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
}
}
{
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();
#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

@@ -0,0 +1,378 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class F>
// explicit packaged_task(F&& f);
#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()
#define BOOST_THREAD_DETAIL_VOID_SIGNATURE void()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
#define BOOST_THREAD_DETAIL_VOID_SIGNATURE void
#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'
#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void(int)
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void()
#endif
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void
#endif
void void_fct()
{
return;
}
double fct()
{
return 5.0;
}
long lfct()
{
return 5;
}
class A
{
public:
long data_;
static int n_moves;
static int n_copies;
BOOST_THREAD_COPYABLE_AND_MOVABLE(A)
static void reset()
{
n_moves=0;
n_copies=0;
}
explicit A(long i) : data_(i)
{
}
A(BOOST_THREAD_RV_REF(A) a) : data_(BOOST_THREAD_RV(a).data_)
{
BOOST_THREAD_RV(a).data_ = -1;
++n_moves;
}
A& operator=(BOOST_THREAD_RV_REF(A) a)
{
data_ = BOOST_THREAD_RV(a).data_;
BOOST_THREAD_RV(a).data_ = -1;
++n_moves;
return *this;
}
A(const A& a) : data_(a.data_)
{
++n_copies;
}
A& operator=(BOOST_THREAD_COPY_ASSIGN_REF(A) a)
{
data_ = a.data_;
++n_copies;
return *this;
}
~A()
{
}
void operator()(int) const
{ }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
{ return data_ + i + j;}
};
int A::n_moves = 0;
int A::n_copies = 0;
class M
{
public:
long data_;
static int n_moves;
BOOST_THREAD_MOVABLE_ONLY(M)
static void reset() {
n_moves=0;
}
explicit M(long i) : data_(i)
{
}
M(BOOST_THREAD_RV_REF(M) a) : data_(BOOST_THREAD_RV(a).data_)
{
BOOST_THREAD_RV(a).data_ = -1;
++n_moves;
}
M& operator=(BOOST_THREAD_RV_REF(M) a)
{
data_ = BOOST_THREAD_RV(a).data_;
BOOST_THREAD_RV(a).data_ = -1;
++n_moves;
return *this;
}
~M()
{
}
void operator()(int) const
{ }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
{ return data_ + i + j;}
};
int M::n_moves = 0;
class C
{
public:
long data_;
static int n_copies;
static void reset()
{
n_copies=0;
}
explicit C(long i) : data_(i)
{
}
C(const C& a) : data_(a.data_)
{
++n_copies;
}
C& operator=(C const& a)
{
data_ = a.data_;
++n_copies;
return *this;
}
~C()
{
}
void operator()(int) const
{ }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
{ return data_ + i + j;}
};
int C::n_copies = 0;
int main()
{
{
A::reset();
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());
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
BOOST_TEST(f.get() == BOOST_THREAD_DETAIL_SIGNATURE_2_RES);
BOOST_TEST(A::n_copies == 0);
BOOST_TEST_EQ(A::n_moves, 1);
}
{
A::reset();
A a(5);
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_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
{
A::reset();
const A a(5);
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_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
{
A::reset();
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(A(5)));
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST(A::n_copies == 0);
BOOST_TEST_EQ(A::n_moves, 1);
}
{
A::reset();
A a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
{
A::reset();
const A a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
#endif
{
M::reset();
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(M(5)));
BOOST_TEST(p.valid());
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)
p(3, 'a');
#else
p();
#endif
BOOST_TEST(f.get() == BOOST_THREAD_DETAIL_SIGNATURE_2_RES);
BOOST_TEST_EQ(M::n_moves, 1);
}
{
M::reset();
M a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(boost::move(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_EQ(M::n_moves, 1);
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
{
M::reset();
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(M(5)));
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(M::n_moves, 1);
}
{
M::reset();
M a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(boost::move(a));
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(M::n_moves, 1);
}
#endif
{
C::reset();
C a(5);
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_EQ(C::n_copies, 1);
}
{
C::reset();
const C a(5);
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_EQ(C::n_copies, 1);
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
{
C::reset();
C a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(C::n_copies, 1);
}
{
C::reset();
const C a(5);
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p(1);
BOOST_TEST_EQ(C::n_copies, 1);
}
#endif
{
boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE> p(void_fct);
BOOST_TEST(p.valid());
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p();
}
{
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');
p();
BOOST_TEST(f.get() == 5.0);
}
{
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');
p();
BOOST_TEST(f.get() == 5.0);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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>
// future<R> get_future();
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
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<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
}
}
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
try
{
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,189 @@
//===----------------------------------------------------------------------===//
//
// 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_mv(BOOST_THREAD_RV_REF(boost::packaged_task<double(int, char)>) p)
//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 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();
#if defined BOOST_THREAD_PROVIDES_VARIADIC_THREAD
boost::thread(func0_mv, boost::move(p)).detach();
#else
boost::thread(func0, &p).detach();
#endif
BOOST_TEST(f.get() == 105.0);
}
{
boost::packaged_task<double(int, char)> p2(A(5));
boost::future<double> f = p2.get_future();
boost::packaged_task<double(int, char)> p = boost::move(p2);
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)> p2(A(5));
boost::future<double> f = p2.get_future();
boost::packaged_task<double(int, char)> p = boost::move(p2);
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)> p2(A(5));
boost::future<double> f = p2.get_future();
boost::packaged_task<double(int, char)> p = boost::move(p2);
boost::thread(func2, &p).detach();
BOOST_TEST(f.get() == 105.0);
}
{
boost::packaged_task<double(int, char)> p(A(5));
//boost::thread t(func3, boost::move(p));
boost::thread t(func3, &p);
t.join();
}
{
boost::packaged_task<double(int, char)> p2(A(5));
boost::packaged_task<double(int, char)> p = boost::move(p2);
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

@@ -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/future.hpp>
// class packaged_task<R>
// void swap(packaged_task& other);
#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>
class A
{
long data_;
public:
explicit A(long i) :
data_(i)
{
}
long operator()() const
{
return data_;
}
long operator()(long i, long j) const
{
return data_ + i + j;
}
};
int main()
{
{
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());
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<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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 promise<R>
// promise& operator=(promise&& rhs);
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
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());
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<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());
}
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 packaged_task<R>
// packaged_task(packaged_task&& other);
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
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());
//p(3, 'a');
p();
BOOST_TEST(f.get() == 5.0);
}
{
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());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class R>
// void
// swap(packaged_task<R>& x, packaged_task<R>& y);
#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>
class A
{
long data_;
public:
explicit A(long i) : data_(i) {}
long operator()() const {return data_;}
long operator()(long i, long j) const {return data_ + i + j;}
};
int main()
{
{
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());
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<BOOST_THREAD_DETAIL_SIGNATURE> p0;
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
p.swap(p0);
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,218 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void operator()();
//#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_;
public:
explicit A(long i) :
data_(i)
{
}
long operator()() const
{
if (data_ == 0) BOOST_THROW_EXCEPTION(E(6));
return data_;
}
long operator()(long i, long j) const
{
if (j == 'z') BOOST_THROW_EXCEPTION(E(6));
return data_ + i + j;
}
~A() {}
};
void func0(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
#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<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
#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<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
p(3, 'a');
#else
p();
#endif
try
{
#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() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
}
void func3(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
{
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));
}
}
int main()
{
{
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();
#else
//p();
#endif
//BOOST_TEST(f.get() == 5.0);
}
{
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 E& e)
{
BOOST_TEST(e.data == 6);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
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));
#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<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

@@ -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 packaged_task<R>
// void operator()();
#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>
class A
{
long data_;
public:
explicit A(long i) :
data_(i)
{
}
long operator()() const
{
return data_;
}
long operator()(long i, long j) const
{
if (j == 'z') throw A(6);
return data_ + i + j;
}
};
int main()
{
{
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);
p.reset();
//p(4, 'a');
p();
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.get() == 5.0);
}
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p;
try
{
p.reset();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template<class R, class... ArgTypes>
// class packaged_task<R(ArgTypes...)>
// {
// public:
// typedef R result_type;
#include <boost/thread/future.hpp>
#include <boost/static_assert.hpp>
#include <boost/detail/lightweight_test.hpp>
struct A {};
int main()
{
//BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::packaged_task<A>::result_type, A>::value), "");
return boost::report_errors();
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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(ArgTypes...)>
// template <class Callable, class Alloc>
// struct uses_allocator<packaged_task<Callable>, Alloc>
// : true_type { };
#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>
#include <boost/static_assert.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
int main()
{
BOOST_STATIC_ASSERT_MSG((boost::csbl::uses_allocator<boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>, test_allocator<double> >::value), "");
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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>
// promise(allocator_arg_t, const Allocator& a);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
int main()
{
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 1);
boost::future<int> 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 == 0);
{
boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 1);
boost::future<int&> 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 == 0);
{
boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
BOOST_TEST(test_alloc_base::count == 1);
boost::future<void> 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 == 0);
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// 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>
// promise& operator=(const promise& rhs) = delete;
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::promise<int> p0;
boost::promise<int> p;
p = p0;
}
return boost::report_errors();
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// promise& operator=(const promise& rhs) = delete;
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::promise<int> p0;
boost::promise<int> p(p0);
}
return boost::report_errors();
}
#include "../../../remove_error_code_unused_warning.hpp"

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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>
// promise();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::promise<int> p;
boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
{
boost::promise<int&> p;
boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
{
boost::promise<void> p;
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
return boost::report_errors();
}

View File

@@ -0,0 +1,116 @@
//===----------------------------------------------------------------------===//
//
// 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>
// ~promise();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
typedef int T;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p.set_value(3);
}
BOOST_TEST(f.get() == 3);
}
{
typedef int T;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
}
try
{
//T i =
(void)f.get();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
}
}
{
typedef int& T;
int i = 4;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p.set_value(i);
}
BOOST_TEST(&f.get() == &i);
}
{
typedef int& T;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
}
try
{
//T i =
(void)f.get();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
}
}
{
typedef void T;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p.set_value();
}
f.get();
BOOST_TEST(true);
}
{
typedef void T;
boost::future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
}
try
{
f.get();
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,207 @@
//===----------------------------------------------------------------------===//
//
// 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,2014 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>
// template <class ...Args>
// void promise::emplace(Args&& ... args);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
struct A
{
A() :
value(0)
{
}
A(int i) :
value(i)
{
}
A(int i, int j) :
value(i+j)
{
}
BOOST_THREAD_MOVABLE_ONLY(A)
A(BOOST_THREAD_RV_REF(A) rhs)
{
if(rhs.value==0)
throw 9;
else
{
value=rhs.value;
rhs.value=0;
}
}
A& operator=(BOOST_THREAD_RV_REF(A) rhs)
{
if(rhs.value==0)
throw 9;
else
{
value=rhs.value;
rhs.value=0;
}
return *this;
}
int value;
};
A make(int i) {
return A(i);
}
A make(int i, int j) {
return A(i, j);
}
struct movable2
{
int value_;
BOOST_THREAD_MOVABLE_ONLY(movable2)
movable2() : value_(1){}
movable2(int i) : value_(i){}
movable2(int i, int j) : value_(i+j){}
//Move constructor and assignment
movable2(BOOST_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; }
movable2 & operator=(BOOST_THREAD_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; return *this; }
bool moved() const //Observer
{ return !value_; }
int value() const //Observer
{ return value_; }
};
movable2 move_return_function2(int i) {
return movable2(i);
}
int main()
{
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_STATIC_ASSERT((boost::is_copy_constructible<movable2>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<movable2>::value == true));
BOOST_STATIC_ASSERT((boost::is_copy_constructible<A>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<A>::value == true));
#endif
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.emplace();
try
{
T a = f.get(); (void)a;
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 9);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.emplace(3);
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);
}
}
{
boost::promise<movable2> p;
boost::future<movable2> f = p.get_future();
p.emplace(3);
BOOST_TEST(f.get().value_ == 3);
try
{
p.emplace(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);
}
}
{
boost::promise<A> p;
boost::future<A> f = p.get_future();
p.emplace(1,2);
BOOST_TEST(f.get().value == 3);
try
{
p.emplace(1,2);
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;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.emplace(3);
boost::promise<T> p2(boost::move(p));
BOOST_TEST(f.get().value == 3);
}
#endif
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>
// future<R> get_future();
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
int main()
{
{
boost::promise<double> p;
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
p.set_value(105.5);
BOOST_TEST(f.get() == 105.5);
}
{
boost::promise<double> p;
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
}
}
{
boost::promise<double> p;
boost::promise<double> p0 = boost::move(p);
try
{
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,155 @@
//===----------------------------------------------------------------------===//
//
// 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 promise<R>
// promise& operator=(promise&& rhs);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
#endif
boost::mutex m0;
boost::mutex m1;
int main()
{
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 2);
p = boost::move(p0);
BOOST_TEST(test_alloc_base::count == 1);
boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
BOOST_TEST(test_alloc_base::count == 1);
}
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 2);
p = boost::move(p0);
BOOST_TEST(test_alloc_base::count == 1);
boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
BOOST_TEST(test_alloc_base::count == 1);
}
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
BOOST_TEST(test_alloc_base::count == 2);
p = boost::move(p0);
BOOST_TEST(test_alloc_base::count == 1);
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
BOOST_TEST(test_alloc_base::count == 1);
}
BOOST_TEST(test_alloc_base::count == 0);
#endif
{
boost::promise<int> p0;
boost::promise<int> p;
p = boost::move(p0);
boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
{
boost::promise<int&> p0;
boost::promise<int&> p;
p = boost::move(p0);
boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
{
boost::promise<void> p0;
boost::promise<void> p;
p = boost::move(p0);
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,151 @@
//===----------------------------------------------------------------------===//
//
// 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 promise<R>
// promise(promise&& rhs);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
#endif
boost::mutex m;
int main()
{
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
boost::promise<int> p(boost::move(p0));
BOOST_TEST(test_alloc_base::count == 1);
std::cout << __LINE__ << std::endl;
boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
std::cout << __LINE__ << std::endl;
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
std::cout << __LINE__ << std::endl;
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
std::cout << __LINE__ << std::endl;
BOOST_TEST(test_alloc_base::count == 1);
}
std::cout << __LINE__ << std::endl;
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
boost::promise<int&> p(boost::move(p0));
BOOST_TEST(test_alloc_base::count == 1);
boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
BOOST_TEST(test_alloc_base::count == 1);
}
BOOST_TEST(test_alloc_base::count == 0);
{
boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
boost::promise<void> p(boost::move(p0));
BOOST_TEST(test_alloc_base::count == 1);
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
BOOST_TEST(test_alloc_base::count == 1);
}
BOOST_TEST(test_alloc_base::count == 0);
#endif
{
boost::promise<int> p0;
boost::promise<int> p(boost::move(p0));
std::cout << __LINE__ << std::endl;
boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
std::cout << __LINE__ << std::endl;
BOOST_TEST(f.valid());
std::cout << __LINE__ << std::endl;
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
std::cout << __LINE__ << std::endl;
}
std::cout << __LINE__ << std::endl;
{
boost::promise<int&> p0;
boost::promise<int&> p(boost::move(p0));
boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
{
boost::promise<void> p0;
boost::promise<void> p(boost::move(p0));
boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
try
{
f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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>
template <typename T>
struct wrap
{
wrap(T const& v) :
value(v)
{
}
T value;
};
template <typename T>
boost::exception_ptr make_exception_ptr(T v)
{
return boost::copy_exception(wrap<T> (v));
}
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
void func(boost::promise<int> p)
#else
boost::promise<int> p;
void func()
#endif
{
//p.set_exception(::make_exception_ptr(3));
p.set_exception_at_thread_exit(::make_exception_ptr(3));
}
int main()
{
{
typedef int T;
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::promise<T> p;
boost::future<T> f = p.get_future();
boost::thread(func, boost::move(p)).detach();
#else
boost::future<T> f = p.get_future();
boost::thread(func).detach();
#endif
try
{
f.get();
BOOST_TEST(false);
}
catch (::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef int T;
boost::promise<T> p2;
boost::future<T> f = p2.get_future();
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::thread(func, boost::move(p2)).detach();
#else
p = boost::move(p2);
boost::thread(func).detach();
#endif
try
{
f.get();
BOOST_TEST(false);
}
catch (::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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>
template <typename T>
struct wrap
{
wrap(T const& v) :
value(v)
{
}
T value;
};
template <typename T>
boost::exception_ptr make_exception_ptr(T v)
{
return boost::copy_exception(wrap<T> (v));
}
int main()
{
{
typedef int T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_exception(::make_exception_ptr(3));
try
{
f.get();
BOOST_TEST(false);
}
catch (::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
try
{
p.set_exception(::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);
}
}
{
typedef int T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_exception_deferred(::make_exception_ptr(3));
BOOST_TEST(!f.is_ready());
p.notify_deferred();
try
{
f.get();
BOOST_TEST(false);
}
catch (::wrap<int> i)
{
BOOST_TEST(i.value == 3);
}
try
{
p.set_exception(::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,132 @@
//===----------------------------------------------------------------------===//
//
// 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);
}
}
{
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_deferred(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 int& T;
int i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value_deferred(i);
BOOST_TEST(!f.is_ready());
p.notify_deferred();
int& j = f.get();
BOOST_TEST(j == 3);
++i;
BOOST_TEST(j == 4);
try
{
p.set_value_deferred(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 int& T;
int i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value_deferred(i);
BOOST_TEST(!f.is_ready());
p.notify_deferred();
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,55 @@
//===----------------------------------------------------------------------===//
//
// 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,2014 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(R&& 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/thread/csbl/memory/unique_ptr.hpp>
boost::promise<boost::csbl::unique_ptr<int> > p;
boost::promise<boost::csbl::unique_ptr<int> > p2;
void func()
{
boost::csbl::unique_ptr<int> uptr(new int(5));
p.set_value_at_thread_exit(boost::move(uptr));
}
void func2()
{
p2.set_value_at_thread_exit(boost::csbl::make_unique<int>(5));
}
int main()
{
{
boost::future<boost::csbl::unique_ptr<int> > f = p.get_future();
boost::thread(func).detach();
BOOST_TEST(*f.get() == 5);
}
{
boost::future<boost::csbl::unique_ptr<int> > f = p2.get_future();
boost::thread(func2).detach();
BOOST_TEST(*f.get() == 5);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,297 @@
//===----------------------------------------------------------------------===//
//
// 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,2014 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>
struct A
{
A() :
value(0)
{
}
A(int i) :
value(i)
{
}
BOOST_THREAD_MOVABLE_ONLY(A)
A(BOOST_THREAD_RV_REF(A) rhs)
{
if(rhs.value==0)
throw 9;
else
{
value=rhs.value;
rhs.value=0;
}
}
A& operator=(BOOST_THREAD_RV_REF(A) rhs)
{
if(rhs.value==0)
throw 9;
else
{
value=rhs.value;
rhs.value=0;
}
return *this;
}
int value;
};
A make(int i) {
return A(i);
}
struct movable2
{
int value_;
BOOST_THREAD_MOVABLE_ONLY(movable2)
movable2() : value_(1){}
movable2(int i) : value_(i){}
//Move constructor and assignment
movable2(BOOST_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; }
movable2 & operator=(BOOST_THREAD_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; return *this; }
bool moved() const //Observer
{ return !value_; }
int value() const //Observer
{ return value_; }
};
movable2 move_return_function2(int i) {
return movable2(i);
}
int main()
{
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_STATIC_ASSERT((boost::is_copy_constructible<movable2>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<movable2>::value == true));
BOOST_STATIC_ASSERT((boost::is_copy_constructible<A>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<A>::value == true));
#endif
{
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;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value_deferred(boost::move(i));
BOOST_TEST(!f.is_ready());
p.notify_deferred();
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 9);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value((T()));
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 9);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value_deferred((T()));
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);
}
}
{
movable2 i(3);
boost::promise<movable2> p;
boost::future<movable2> f = p.get_future();
p.set_value(move_return_function2(3));
BOOST_TEST(f.get().value_ == 3);
try
{
movable2 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);
}
}
{
boost::promise<A> p;
boost::future<A> f = p.get_future();
p.set_value(make(3));
BOOST_TEST(f.get().value == 3);
try
{
A 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);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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>
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
void func(boost::promise<int> p)
#else
boost::promise<int> p;
void func()
#endif
{
const int i = 5;
p.set_value_at_thread_exit(i);
}
int main()
{
{
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
boost::promise<int> p;
boost::future<int> f = p.get_future();
boost::thread(func, boost::move(p)).detach();
#else
boost::future<int> f = p.get_future();
boost::thread(func).detach();
#endif
try
{
BOOST_TEST(f.get() == 5);
}
catch (...)
{
BOOST_TEST(false);
}
}
{
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#else
boost::promise<int> p2;
boost::future<int> f = p2.get_future();
p = boost::move(p2);
boost::thread(func).detach();
BOOST_TEST(f.get() == 5);
#endif
}
return boost::report_errors();
}

View File

@@ -0,0 +1,110 @@
//===----------------------------------------------------------------------===//
//
// 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_mv(BOOST_THREAD_RV_REF(boost::promise<void>) p2)
void func2_mv(boost::promise<void> p2)
{
p2.set_value_at_thread_exit();
i = 2;
}
void func2(boost::promise<void> *p2)
{
p2->set_value_at_thread_exit();
i = 2;
}
int main()
{
try
{
boost::future<void> f = p.get_future();
boost::thread(func).detach();
f.get();
BOOST_TEST(i == 1);
}
catch(std::exception& )
{
BOOST_TEST(false);
}
catch(...)
{
BOOST_TEST(false);
}
try
{
boost::promise<void> p2;
boost::future<void> f = p2.get_future();
p = boost::move(p2);
boost::thread(func).detach();
f.get();
BOOST_TEST(i == 1);
}
catch(std::exception& ex)
{
std::cout << __FILE__ << ":" << __LINE__ << " " << ex.what() << std::endl;
BOOST_TEST(false);
}
catch(...)
{
BOOST_TEST(false);
}
try
{
boost::promise<void> p2;
boost::future<void> f = p2.get_future();
#if defined BOOST_THREAD_PROVIDES_VARIADIC_THREAD
boost::thread(func2_mv, boost::move(p2)).detach();
#else
boost::thread(func2, &p2).detach();
#endif
f.wait();
f.get();
BOOST_TEST(i == 2);
}
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,118 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <boost/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(disable: 4702) // unreachable code
#endif
struct A
{
A()
{
}
A(const A&)
{
throw 10;
}
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
A& operator= (const A&) = default;
#endif
};
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 int T;
T i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value_deferred(i);
p.notify_deferred();
++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,84 @@
//===----------------------------------------------------------------------===//
//
// 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);
}
}
{
typedef void T;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value_deferred();
p.notify_deferred();
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,47 @@
//===----------------------------------------------------------------------===//
//
// 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>
// promise(allocator_arg_t, const Allocator& a);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
int main()
{
BOOST_STATIC_ASSERT_MSG((boost::csbl::uses_allocator<boost::promise<int>, test_allocator<int> >::value), "");
BOOST_STATIC_ASSERT_MSG((boost::csbl::uses_allocator<boost::promise<int&>, test_allocator<int&> >::value), "");
BOOST_STATIC_ASSERT_MSG((boost::csbl::uses_allocator<boost::promise<void>, test_allocator<void> >::value), "");
return boost::report_errors();
}
#else
int main()
{
return boost::report_errors();
}
#endif

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,205 @@
//===----------------------------------------------------------------------===//
//
// 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
template <typename T>
struct wrap
{
wrap(T const& v) : value(v){}
T value;
};
template <typename T>
boost::exception_ptr make_exception_ptr(T v) {
return boost::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(::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(::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(::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(::make_exception_ptr(3));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (::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(::make_exception_ptr(3.5));
#endif
try
{
BOOST_TEST(f.valid());
BOOST_TEST(f.get() == 3);
BOOST_TEST(false);
}
catch (::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(::make_exception_ptr(4));
#endif
try
{
BOOST_TEST(f.valid());
f.get();
BOOST_TEST(false);
}
catch (::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();
}

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