mirror of
https://github.com/boostorg/thread.git
synced 2026-02-03 21:52:07 +00:00
Compare commits
8 Commits
feature/sc
...
feature/ta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ad389bdd | ||
|
|
69c1d40750 | ||
|
|
c3b98129e4 | ||
|
|
3891eeef52 | ||
|
|
f1370b1255 | ||
|
|
69f2a1df72 | ||
|
|
700301e382 | ||
|
|
952aa44a98 |
@@ -10,7 +10,7 @@
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3785.pdf [*N3785 - Executors and Schedulers revision 3]] C++1y proposal from Chris Mysen, Niklas Gustafsson, Matt Austern, Jeffrey Yasskin. The text that follows has been adapted from tis paper to show the differences.]
|
||||
[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3785.pdf [*N3785 - Executors and Schedulers revision 3]] C++1y proposal from Chris Mysen, Niklas Gustafsson, Matt Austern, Jeffrey Yasskin. The text that follows has been adapted from this paper to show the differences.]
|
||||
|
||||
Executors are objects that can execute units of work packaged as function objects. Boost.Thread differs from N3785 mainly in the an Executor doesn't needs to inherit from an abstract class Executor. Static polymorphism is used instead and type erasure is used internally.
|
||||
|
||||
|
||||
@@ -8,6 +8,40 @@
|
||||
|
||||
[section:changes History]
|
||||
|
||||
[heading Version 4.5.0 - boost 1.58]
|
||||
|
||||
[*Know Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2442 #2442] Application statically linked with Boost.Thread crashes when Google Desktop is installed (Windows XP)
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3926 #3926] thread_specific_ptr + dlopen library causes a SIGSEGV.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4833 #4833] MinGW/test_tss_lib: Support of automatic tss cleanup for native threading API not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7319 #7319] Take care of c++std-lib-32966 issue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8600 #8600] wait_for_any hangs, if called with multiple copies of shared_future referencing same task
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9118 #9118] Seg fault on thread join when llvm and libc++ are used
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9309 #9309] test_latch fails often on clang-darwin-tot11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9311 #9311] ex_lambda_future fails on msvc-11.0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10537 #10537] Application crash on throw exception
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10651 #10651] boost::thread leaks memory when using the MinGW compiler
|
||||
|
||||
Please take a look at [@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=thread&type=!Feature+Requests&col=id&col=summary&order=id thread Know Bugs] to see the current state.
|
||||
|
||||
Please take a look at [@http://www.boost.org/development/tests/master/developer/thread.html thread trunk regression test] to see the last snapshot.
|
||||
|
||||
[*Sever limitations:]
|
||||
|
||||
There are some severe bugs that prevent the use of the library on concrete contexts, in particular:
|
||||
|
||||
* on thread specific storage that prevent the library to be used with dynamic libraries,
|
||||
|
||||
[*New Experimental Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9600 #9600] Async: Add task_region
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10611 #10611] Add emplace promise::set_value and emplace make_ready_future
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
|
||||
[heading Version 4.4.0 - boost 1.57]
|
||||
|
||||
[*Know Bugs:]
|
||||
@@ -557,9 +591,6 @@ been moved to __thread_id__.
|
||||
|
||||
The following features will be included in next releases.
|
||||
|
||||
# Complete the C++11 missing features, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6227 #6227] C++11 compliance: Use of variadic templates on Generic Locking Algorithms on compilers providing them.
|
||||
|
||||
# Add some minor features, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7589 #7589] Synchro: Add polymorphic lockables.
|
||||
|
||||
@@ -567,9 +598,6 @@ The following features will be included in next releases.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8273 #8273] Synchro: Add externally locked streams.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8514 #8514] Async: Add a thread_pool executor with work stealing.
|
||||
|
||||
# Add extensions related to fork-join as:
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9600 #9600] Async: Add task_region/task_run.
|
||||
|
||||
# And some additional extensions related to futures as:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8517 #8517] Async: Add a variadic shared_future::then.
|
||||
|
||||
482
doc/parallel.qbk
Normal file
482
doc/parallel.qbk
Normal file
@@ -0,0 +1,482 @@
|
||||
[/
|
||||
/ 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)
|
||||
/]
|
||||
|
||||
[//////////////////////////////////////////////////////////]
|
||||
[section:parallel Parallel - Fork-Join -- EXPERIMENTAL]
|
||||
|
||||
[section:fork_join Fork-Join]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4088.pdf [* n4088 - Task Region R3]] C++1y proposal from P. Halpern, A. Robison, A. Laksberg, H. Sutter, et al. The text that follows has been adapted from this paper to show the differences.]
|
||||
|
||||
The major difference respect to the standard proposal is that we are able to use a common executor for several task regions.
|
||||
|
||||
[note
|
||||
Up to now, Boost.Thread doesn't implement the parallel algorithms as defined in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4105.pdf [* n4105 - Information technology – Programming languages, their environments and system software interfaces – Technical Specification for C++ Extensions for Parallelism]].
|
||||
]
|
||||
|
||||
[////////////////////]
|
||||
[section Introduction]
|
||||
|
||||
|
||||
This module introduces a C++11/c++14 library function template `task_region` and a library class `task_region_handle`
|
||||
with member functions `run` and `wait` that together enable developers to write expressive and portable fork-join
|
||||
parallel code.
|
||||
|
||||
The working draft for the Parallelism TS [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4105.pdf [*N4105]] augments the STL algorithms with the inclusion of parallel execution policies. Programmers use these as a basis to write additional high-level algorithms that can be implemented in terms of the provided parallel algorithms. However, the scope of n4105 does not include lower-level mechanisms to express arbitrary fork-join parallelism
|
||||
|
||||
The `task_region`, `run` and the `wait` functions provided by this library are based on the `task_group` concept that is a part of the common subset of the PPL and the TBB libraries.
|
||||
|
||||
[endsect] [/ Introduction]
|
||||
|
||||
|
||||
[/////////////////////////]
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
Consider an example of a parallel traversal of a tree, where a user-provided function compute is applied to each node of the tree, returning the sum of the results:
|
||||
|
||||
template<typename Func>
|
||||
int traverse(node *n, Func&& compute)
|
||||
{
|
||||
int left = 0, right = 0;
|
||||
task_region([&](task_region_handle& tr) {
|
||||
if (n->left)
|
||||
tr.run([&] { left = traverse(n->left, compute); });
|
||||
if (n->right)
|
||||
tr.run([&] { right = traverse(n->right, compute); });
|
||||
});
|
||||
return compute(n) + left + right;
|
||||
}
|
||||
|
||||
The example above demonstrates the use of two of the functions proposed in this paper, `task_region` and
|
||||
`task_region_handle::run`.
|
||||
The `task_region` function delineates a region in a program code potentially containing invocations of tasks
|
||||
spawned by the `run` member function of the `task_region_handle` class.
|
||||
|
||||
The run function spawns a task, a unit of work that is allowed to execute in parallel with respect to the caller.
|
||||
Any parallel tasks spawned by `run` within the `task_region` are joined back to a single thread of execution at
|
||||
the end of the `task_region`.
|
||||
|
||||
`run` takes a user-provided function object `f` and starts it asynchronously - i.e. it may return before the
|
||||
execution of `f` completes. The implementation's scheduler may choose to run `f` immediately or delay running
|
||||
`f` until compute resources become available.
|
||||
|
||||
A `task_region_handle` can be constructed only by `task_region` because it has no public constructors.
|
||||
Thus, `run` can be invoked (directly or indirectly) only from a user-provided function passed to `task_region`:
|
||||
|
||||
void g();
|
||||
void f(task_region_handle& tr)
|
||||
{
|
||||
tr.run(g); // OK, invoked from within task_region in h
|
||||
}
|
||||
void h()
|
||||
{
|
||||
task_region(f);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
task_region_handle tr; // Error: no public constructor
|
||||
tr.run(g); // No way to call run outside of a task_region
|
||||
return 0;
|
||||
}
|
||||
|
||||
[endsect] [/ Tutorial]
|
||||
|
||||
[////////////////]
|
||||
[section:examples Examples]
|
||||
|
||||
[section:fib Parallel Fibonacci]
|
||||
|
||||
|
||||
This is surely the worst implementation of the Fibonacci function. Anyway, here it is, as it is simple and shows the fork-join structure clearly. `Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)`, so the task decomposition is trivial.
|
||||
|
||||
int fib_task_region(int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region([&](task_region_handle& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
[endsect] [/ Fib]
|
||||
[section:fibex Parallel Fibonacci - Specific executor]
|
||||
|
||||
The previous example make use of an implementation defined way to spawn the tasks. Often the user wants to master how the task must be spawned. There is an overload of `task_region` that accept an additional `Executor` parameter and a function that takes as parameter a `task_region_handle_gen<Executor>`. `task_region_handle_gen<Executor>` run uses this executor to spawn the tasks.
|
||||
|
||||
template <class Ex>
|
||||
int fib_task_region_gen( Ex& ex, int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle_gen;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region(ex, [&](task_region_handle_gen<Ex>& trh) // (2)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::basic_thread_pool tp; // (1)
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region_gen(tp,i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
The specific executor is declared in line (1) and it is used in line (2).
|
||||
|
||||
[endsect] [/ Fib ex]
|
||||
|
||||
|
||||
|
||||
|
||||
[section:quick_sort Parallel Accumulate]
|
||||
|
||||
|
||||
[endsect] [/ Accumulate]
|
||||
|
||||
[section:quick_sort Parallel Quick Sort]
|
||||
|
||||
|
||||
|
||||
[endsect] [/ QuickSort]
|
||||
[endsect] [/ Examples]
|
||||
|
||||
|
||||
[////////////////////////]
|
||||
[section:rationale Design Rationale]
|
||||
|
||||
|
||||
[endsect] [/ Design Rationale]
|
||||
[endsect] [/ Fork-Join]
|
||||
|
||||
[/////////////////////]
|
||||
[section:ref Reference -- EXPERIMENTAL]
|
||||
|
||||
[/////////////////////////]
|
||||
[section:v1 Parallel V1]
|
||||
|
||||
[section:exception_list Header `<experimental/exception_list.hpp>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v1
|
||||
{
|
||||
|
||||
class exception_list;
|
||||
|
||||
} // v1
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[/////////////////////////]
|
||||
[section:exception_list Class `exception_list`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v1
|
||||
{
|
||||
|
||||
class exception_list: public std::exception
|
||||
{
|
||||
public:
|
||||
typedef 'implementation defined' const_iterator;
|
||||
|
||||
~exception_list() noexcept {}
|
||||
|
||||
void add(exception_ptr const& e);
|
||||
size_t size() const noexcept;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const char* what() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
} // v1
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[endsect] [/ exception_list]
|
||||
|
||||
[endsect] [/ exception_list.hpp]
|
||||
|
||||
[endsect] [/ Parallel V1]
|
||||
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:v2 Parallel V2]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:concepts Concepts]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:regionCallable Concept `Region_Callable`]
|
||||
|
||||
[endsect] [/ Region_Callable]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:taskCallable Concept `Task_Callable`]
|
||||
|
||||
|
||||
[endsect] [/ Task_Callable]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[endsect] [/ Concepts]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region Header `<experimental/task_region.hpp>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_canceled_exception;
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen;
|
||||
|
||||
using default_executor = 'implementation defined';
|
||||
|
||||
class task_region_handle;
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region_final(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region_final(F&& f);
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_canceled_exception Class `task_canceled_exception `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_canceled_exception: public std::exception
|
||||
{
|
||||
public:
|
||||
task_canceled_exception() noexcept;
|
||||
task_canceled_exception(const task_canceled_exception&) noexcept;
|
||||
task_canceled_exception& operator=(const task_canceled_exception&) noexcept;
|
||||
virtual const char* what() const noexcept;
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_canceled_exception]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_handle_gen Template Class `task_region_handle_gen<>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen
|
||||
{
|
||||
protected:
|
||||
task_region_handle_gen(Executor& ex);
|
||||
|
||||
~task_region_handle_gen();
|
||||
|
||||
public:
|
||||
task_region_handle_gen(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen& operator=(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen* operator&() const = delete;
|
||||
|
||||
template<typename F>
|
||||
void run(F&& f);
|
||||
|
||||
void wait();
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_handle_gen]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:default_executor Class `default_executor `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
using default_executor = 'implementation defined';
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ default_executor]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_handle Class `task_region_handle `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_region_handle :
|
||||
public task_region_handle_gen<default_executor>
|
||||
{
|
||||
protected:
|
||||
task_region_handle();
|
||||
task_region_handle(const task_region_handle&) = delete;
|
||||
task_region_handle& operator=(const task_region_handle&) = delete;
|
||||
task_region_handle* operator&() const = delete;
|
||||
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_handle]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_final Template Function `task_region_final `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region_final(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region_final(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_final]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region Template Function `task_region `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect] [/ task_region.hpp]
|
||||
[endsect] [/ Parallel V2]
|
||||
[endsect] [/ Reference]
|
||||
|
||||
[endsect] [/ Parallel]
|
||||
@@ -244,7 +244,6 @@
|
||||
[include futures.qbk]
|
||||
[endsect]
|
||||
|
||||
|
||||
[include tss.qbk]
|
||||
|
||||
[section:sds Synchronized Data Structures]
|
||||
@@ -253,6 +252,8 @@
|
||||
[/include sync_streams.qbk]
|
||||
[endsect]
|
||||
|
||||
[include parallel.qbk]
|
||||
|
||||
[include time.qbk]
|
||||
|
||||
[include emulations.qbk]
|
||||
|
||||
91
example/fib_task_region.cpp
Normal file
91
example/fib_task_region.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2012 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)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
|
||||
#include <boost/thread/experimental/task_region.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#if ! defined BOOST_NO_CXX11_RANGE_BASED_FOR && ! defined BOOST_NO_CXX11_LAMBDAS
|
||||
|
||||
int fib_task_region(int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region([&](task_region_handle& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
template <class Ex>
|
||||
int fib_task_region_gen( Ex& ex, int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle_gen;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region(ex, [&](task_region_handle_gen<Ex>& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
boost::basic_thread_pool tp;
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region_gen(tp,i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_CONFIG_INLINE_NAMESPACE_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_CONFIG_INLINE_NAMESPACE_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
|
||||
# define BOOST_THREAD_INLINE_NAMESPACE(name) inline namespace name
|
||||
#else
|
||||
# define BOOST_THREAD_INLINE_NAMESPACE(name) namespace name
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
16
include/boost/thread/experimental/exception_list.hpp
Normal file
16
include/boost/thread/experimental/exception_list.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_EXCEPTION_LIST_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_EXCEPTION_LIST_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/experimental/parallel/v1/exception_list.hpp>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_PARALLEL_V1_EXCEPTION_LIST_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_PARALLEL_V1_EXCEPTION_LIST_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/experimental/parallel/v1/inline_namespace.hpp>
|
||||
|
||||
#include <boost/exception_ptr.hpp>
|
||||
#include <exception>
|
||||
#include <list>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
BOOST_THREAD_INLINE_NAMESPACE(v1)
|
||||
{
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE exception_list: public std::exception
|
||||
{
|
||||
typedef std::list<exception_ptr> exception_ptr_list;
|
||||
exception_ptr_list list_;
|
||||
public:
|
||||
typedef exception_ptr_list::const_iterator const_iterator;
|
||||
|
||||
~exception_list() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
|
||||
void add(exception_ptr const& e)
|
||||
{
|
||||
list_.push_back(e);
|
||||
}
|
||||
size_t size() const BOOST_NOEXCEPT
|
||||
{
|
||||
return list_.size();
|
||||
}
|
||||
const_iterator begin() const BOOST_NOEXCEPT
|
||||
{
|
||||
return list_.begin();
|
||||
}
|
||||
const_iterator end() const BOOST_NOEXCEPT
|
||||
{
|
||||
return list_.end();
|
||||
}
|
||||
const char* what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
return "exception_list";
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_PARALLEL_V1_INLINE_NAMESPACE_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_PARALLEL_V1_INLINE_NAMESPACE_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/experimental/config/inline_namespace.hpp>
|
||||
namespace boost {
|
||||
namespace experimental {
|
||||
namespace parallel {
|
||||
|
||||
BOOST_THREAD_INLINE_NAMESPACE(v1) {}
|
||||
|
||||
#if defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
|
||||
using namespace v1;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_PARALLEL_V2_INLINE_NAMESPACE_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_PARALLEL_V2_INLINE_NAMESPACE_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/experimental/config/inline_namespace.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace experimental {
|
||||
namespace parallel {
|
||||
|
||||
BOOST_THREAD_INLINE_NAMESPACE(v2) {}
|
||||
|
||||
#if defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
|
||||
using namespace v2;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
316
include/boost/thread/experimental/parallel/v2/task_region.hpp
Executable file
316
include/boost/thread/experimental/parallel/v2/task_region.hpp
Executable file
@@ -0,0 +1,316 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_PARALLEL_V2_TASK_REGION_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_PARALLEL_V2_TASK_REGION_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#if ! defined BOOST_NO_CXX11_RANGE_BASED_FOR
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#endif
|
||||
#include <boost/thread/experimental/exception_list.hpp>
|
||||
#include <boost/thread/experimental/parallel/v2/inline_namespace.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
#define BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
BOOST_THREAD_INLINE_NAMESPACE(v2)
|
||||
{
|
||||
class BOOST_SYMBOL_VISIBLE task_canceled_exception: public std::exception
|
||||
{
|
||||
public:
|
||||
//task_canceled_exception() BOOST_NOEXCEPT {}
|
||||
//task_canceled_exception(const task_canceled_exception&) BOOST_NOEXCEPT {}
|
||||
//task_canceled_exception& operator=(const task_canceled_exception&) BOOST_NOEXCEPT {}
|
||||
virtual const char* what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return "task_canceled_exception";}
|
||||
};
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void handle_task_region_exceptions(exception_list& errors)
|
||||
{
|
||||
try {
|
||||
boost::rethrow_exception(boost::current_exception());
|
||||
//throw boost::current_exception();
|
||||
}
|
||||
catch (task_canceled_exception& ex)
|
||||
{
|
||||
}
|
||||
catch (exception_list const& el)
|
||||
{
|
||||
for (boost::exception_ptr const& e: el)
|
||||
{
|
||||
try {
|
||||
rethrow_exception(e);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
handle_task_region_exceptions(errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
errors.add(boost::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
template <class TRH, class F>
|
||||
struct wrapped
|
||||
{
|
||||
TRH& tr;
|
||||
F f;
|
||||
wrapped(TRH& tr, F&& f) : tr(tr), f(move(f))
|
||||
{}
|
||||
void operator()()
|
||||
{
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
lock_guard<mutex> lk(tr.mtx);
|
||||
tr.canceled = true;
|
||||
handle_task_region_exceptions(tr.exs);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen
|
||||
{
|
||||
private:
|
||||
// Private members and friends
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
template <class TRH, class F>
|
||||
friend struct detail::wrapped;
|
||||
#endif
|
||||
template <typename F>
|
||||
friend void task_region(F&& f);
|
||||
template<typename F>
|
||||
friend void task_region_final(F&& f);
|
||||
template <class Ex, typename F>
|
||||
friend void task_region(Ex&, F&& f);
|
||||
template<class Ex, typename F>
|
||||
friend void task_region_final(Ex&, F&& f);
|
||||
|
||||
void wait_all()
|
||||
{
|
||||
wait_for_all(group.begin(), group.end());
|
||||
|
||||
#if ! defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
|
||||
for (future<void>& f: group)
|
||||
{
|
||||
if (f.has_exception())
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::rethrow_exception(f.get_exception_ptr());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
detail::handle_task_region_exceptions(exs);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (exs.size() != 0)
|
||||
{
|
||||
boost::throw_exception(exs);
|
||||
//throw exs;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
#if ! defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED && ! defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
task_region_handle_gen()
|
||||
{}
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED && defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
task_region_handle_gen()
|
||||
: canceled(false)
|
||||
, ex(0)
|
||||
{}
|
||||
task_region_handle_gen(Executor& ex)
|
||||
: canceled(false)
|
||||
, ex(&ex)
|
||||
{}
|
||||
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED && defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
task_region_handle_gen()
|
||||
: ex(0)
|
||||
{}
|
||||
task_region_handle_gen(Executor& ex)
|
||||
: ex(&ex)
|
||||
{}
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED && ! defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
task_region_handle_gen()
|
||||
: canceled(false)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~task_region_handle_gen()
|
||||
{
|
||||
//wait_all();
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
bool canceled;
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
Executor* ex;
|
||||
#endif
|
||||
exception_list exs;
|
||||
csbl::vector<future<void>> group;
|
||||
mutable mutex mtx;
|
||||
|
||||
|
||||
public:
|
||||
task_region_handle_gen(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen& operator=(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen* operator&() const = delete;
|
||||
|
||||
template<typename F>
|
||||
void run(F&& f)
|
||||
{
|
||||
lock_guard<mutex> lk(mtx);
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
if (canceled) {
|
||||
boost::throw_exception(task_canceled_exception());
|
||||
//throw task_canceled_exception();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
group.push_back(async(*ex, detail::wrapped<task_region_handle_gen<Executor>, F>(*this, forward<F>(f))));
|
||||
#else
|
||||
group.push_back(async(detail::wrapped<task_region_handle_gen<Executor>, F>(*this, forward<F>(f))));
|
||||
#endif
|
||||
#else
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
group.push_back(async(*ex, forward<F>(f)));
|
||||
#else
|
||||
group.push_back(async(forward<F>(f)));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
lock_guard<mutex> lk(mtx);
|
||||
#if defined BOOST_THREAD_TASK_REGION_HAS_SHARED_CANCELED
|
||||
if (canceled) {
|
||||
boost::throw_exception(task_canceled_exception());
|
||||
//throw task_canceled_exception{};
|
||||
}
|
||||
#endif
|
||||
wait_all();
|
||||
}
|
||||
};
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
typedef basic_thread_pool default_executor;
|
||||
#else
|
||||
typedef int default_executor;
|
||||
#endif
|
||||
class task_region_handle :
|
||||
public task_region_handle_gen<default_executor>
|
||||
{
|
||||
default_executor tp;
|
||||
template <typename F>
|
||||
friend void task_region(F&& f);
|
||||
template<typename F>
|
||||
friend void task_region_final(F&& f);
|
||||
|
||||
protected:
|
||||
task_region_handle() : task_region_handle_gen<default_executor>()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
ex = &tp;
|
||||
#endif
|
||||
}
|
||||
task_region_handle(const task_region_handle&) = delete;
|
||||
task_region_handle& operator=(const task_region_handle&) = delete;
|
||||
task_region_handle* operator&() const = delete;
|
||||
|
||||
};
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region_final(Executor& ex, F&& f)
|
||||
{
|
||||
task_region_handle_gen<Executor> tr(ex);
|
||||
try
|
||||
{
|
||||
f(tr);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
lock_guard<mutex> lk(tr.mtx);
|
||||
detail::handle_task_region_exceptions(tr.exs);
|
||||
}
|
||||
tr.wait_all();
|
||||
}
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region(Executor& ex, F&& f)
|
||||
{
|
||||
task_region_final(ex, forward<F>(f));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void task_region_final(F&& f)
|
||||
{
|
||||
task_region_handle tr;
|
||||
try
|
||||
{
|
||||
f(tr);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
lock_guard<mutex> lk(tr.mtx);
|
||||
detail::handle_task_region_exceptions(tr.exs);
|
||||
}
|
||||
tr.wait_all();
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void task_region(F&& f)
|
||||
{
|
||||
task_region_final(forward<F>(f));
|
||||
}
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
#endif
|
||||
16
include/boost/thread/experimental/task_region.hpp
Normal file
16
include/boost/thread/experimental/task_region.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef BOOST_THREAD_EXPERIMENTAL_TASK_REGION_HPP
|
||||
#define BOOST_THREAD_EXPERIMENTAL_TASK_REGION_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2014. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/experimental/parallel/v2/task_region.hpp>
|
||||
|
||||
#endif
|
||||
@@ -432,24 +432,24 @@ namespace boost
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
void mark_interrupted_finish()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(this->mutex);
|
||||
exception = boost::copy_exception(boost::thread_interrupted());
|
||||
mark_finished_internal(lock);
|
||||
}
|
||||
// void mark_interrupted_finish()
|
||||
// {
|
||||
// boost::unique_lock<boost::mutex> lock(this->mutex);
|
||||
// exception = boost::copy_exception(boost::thread_interrupted());
|
||||
// mark_finished_internal(lock);
|
||||
// }
|
||||
|
||||
void set_interrupted_at_thread_exit()
|
||||
{
|
||||
unique_lock<boost::mutex> lk(this->mutex);
|
||||
if (has_value(lk))
|
||||
{
|
||||
throw_exception(promise_already_satisfied());
|
||||
}
|
||||
exception = boost::copy_exception(boost::thread_interrupted());
|
||||
this->is_constructed = true;
|
||||
detail::make_ready_at_thread_exit(shared_from_this());
|
||||
}
|
||||
// void set_interrupted_at_thread_exit()
|
||||
// {
|
||||
// unique_lock<boost::mutex> lk(this->mutex);
|
||||
// if (has_value(lk))
|
||||
// {
|
||||
// throw_exception(promise_already_satisfied());
|
||||
// }
|
||||
// exception = boost::copy_exception(boost::thread_interrupted());
|
||||
// this->is_constructed = true;
|
||||
// detail::make_ready_at_thread_exit(shared_from_this());
|
||||
// }
|
||||
#endif
|
||||
|
||||
void set_exception_at_thread_exit(exception_ptr e)
|
||||
@@ -481,14 +481,14 @@ namespace boost
|
||||
return done && exception;
|
||||
}
|
||||
|
||||
bool has_exception(unique_lock<boost::mutex>&) const
|
||||
{
|
||||
return done && exception;
|
||||
}
|
||||
// bool has_exception(unique_lock<boost::mutex>&) const
|
||||
// {
|
||||
// return done && exception;
|
||||
// }
|
||||
|
||||
bool is_deferred(boost::lock_guard<boost::mutex>&) const {
|
||||
return is_deferred_;
|
||||
}
|
||||
// bool is_deferred(boost::lock_guard<boost::mutex>&) const {
|
||||
// return is_deferred_;
|
||||
// }
|
||||
|
||||
launch launch_policy(boost::unique_lock<boost::mutex>&) const
|
||||
{
|
||||
@@ -511,13 +511,14 @@ namespace boost
|
||||
exception_ptr get_exception_ptr()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(this->mutex);
|
||||
return get_exception_ptr(lock);
|
||||
}
|
||||
exception_ptr get_exception_ptr(boost::unique_lock<boost::mutex>& lock)
|
||||
{
|
||||
wait_internal(lock, false);
|
||||
return exception;
|
||||
}
|
||||
// exception_ptr get_exception_ptr(boost::unique_lock<boost::mutex>& lock)
|
||||
// {
|
||||
// wait_internal(lock, false);
|
||||
// return exception;
|
||||
// }
|
||||
|
||||
template<typename F,typename U>
|
||||
void set_wait_callback(F f,U* u)
|
||||
@@ -580,21 +581,29 @@ namespace boost
|
||||
|
||||
void mark_finished_with_result_internal(rvalue_source_type result_, boost::unique_lock<boost::mutex>& lock)
|
||||
{
|
||||
#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
#if defined BOOST_THREAD_FUTURE_USES_OPTIONAL
|
||||
result = boost::move(result_);
|
||||
#else
|
||||
#elif ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
result.reset(new T(boost::move(result_)));
|
||||
#endif
|
||||
#else
|
||||
#if defined BOOST_THREAD_FUTURE_USES_OPTIONAL
|
||||
result = boost::move(result_);
|
||||
#else
|
||||
result.reset(new T(static_cast<rvalue_source_type>(result_)));
|
||||
#endif
|
||||
this->mark_finished_internal(lock);
|
||||
}
|
||||
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <class ...Args>
|
||||
void mark_finished_with_result_internal(boost::unique_lock<boost::mutex>& lock, BOOST_THREAD_FWD_REF(Args)... args)
|
||||
{
|
||||
#if defined BOOST_THREAD_FUTURE_USES_OPTIONAL
|
||||
result.emplace(boost::forward<Args>(args)...);
|
||||
#else
|
||||
result.reset(new T(boost::forward<Args>(args)...));
|
||||
#endif
|
||||
this->mark_finished_internal(lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
void mark_finished_with_result(source_reference_type result_)
|
||||
{
|
||||
@@ -830,12 +839,6 @@ namespace boost
|
||||
{
|
||||
that->mark_finished_with_result(f());
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
that->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
that->mark_exceptional_finish();
|
||||
@@ -858,12 +861,6 @@ namespace boost
|
||||
f();
|
||||
that->mark_finished_with_result();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
that->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
that->mark_exceptional_finish();
|
||||
@@ -885,12 +882,6 @@ namespace boost
|
||||
{
|
||||
that->mark_finished_with_result(f());
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
that->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
that->mark_exceptional_finish();
|
||||
@@ -1277,7 +1268,6 @@ namespace boost
|
||||
future_ = p.get_future().future_;
|
||||
}
|
||||
|
||||
|
||||
future_ptr future_;
|
||||
|
||||
basic_future(future_ptr a_future):
|
||||
@@ -2077,6 +2067,22 @@ namespace boost
|
||||
future_->mark_finished_with_result_internal(static_cast<rvalue_source_type>(r), lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <class ...Args>
|
||||
void emplace(BOOST_THREAD_FWD_REF(Args) ...args)
|
||||
{
|
||||
lazy_init();
|
||||
boost::unique_lock<boost::mutex> lock(future_->mutex);
|
||||
if(future_->done)
|
||||
{
|
||||
boost::throw_exception(promise_already_satisfied());
|
||||
}
|
||||
future_->mark_finished_with_result_internal(lock, boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void set_exception(boost::exception_ptr p)
|
||||
{
|
||||
lazy_init();
|
||||
@@ -2606,12 +2612,12 @@ namespace boost
|
||||
this->set_value_at_thread_exit(f());
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -2637,12 +2643,6 @@ namespace boost
|
||||
this->mark_finished_with_result(f());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
@@ -2693,12 +2693,12 @@ namespace boost
|
||||
this->set_value_at_thread_exit(f());
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -2720,12 +2720,6 @@ namespace boost
|
||||
R& res((f()));
|
||||
this->mark_finished_with_result(res);
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
@@ -2783,12 +2777,12 @@ namespace boost
|
||||
this->set_value_at_thread_exit(boost::move(r));
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -2811,12 +2805,6 @@ namespace boost
|
||||
R res((f()));
|
||||
this->mark_finished_with_result(boost::move(res));
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
@@ -2870,12 +2858,12 @@ namespace boost
|
||||
this->set_value_at_thread_exit(f());
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -2897,12 +2885,6 @@ namespace boost
|
||||
{
|
||||
this->mark_finished_with_result(f());
|
||||
}
|
||||
#endif
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
@@ -2953,12 +2935,12 @@ namespace boost
|
||||
#endif
|
||||
this->set_value_at_thread_exit();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -2980,12 +2962,6 @@ namespace boost
|
||||
#endif
|
||||
this->mark_finished_with_result();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
this->mark_exceptional_finish();
|
||||
@@ -3032,12 +3008,12 @@ namespace boost
|
||||
#endif
|
||||
this->set_value_at_thread_exit();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->set_interrupted_at_thread_exit();
|
||||
}
|
||||
#endif
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
// catch(thread_interrupted& )
|
||||
// {
|
||||
// this->set_interrupted_at_thread_exit();
|
||||
// }
|
||||
//#endif
|
||||
catch(...)
|
||||
{
|
||||
this->set_exception_at_thread_exit(current_exception());
|
||||
@@ -3059,12 +3035,6 @@ namespace boost
|
||||
#endif
|
||||
this->mark_finished_with_result();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
catch(thread_interrupted& )
|
||||
{
|
||||
this->mark_interrupted_finish();
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
this->mark_exceptional_finish();
|
||||
@@ -3602,10 +3572,6 @@ namespace detail {
|
||||
void operator()() {
|
||||
try {
|
||||
that->mark_finished_with_result(f_());
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif // defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -3653,10 +3619,6 @@ namespace detail {
|
||||
try {
|
||||
f_();
|
||||
that->mark_finished_with_result();
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif // defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -3702,10 +3664,6 @@ namespace detail {
|
||||
void operator()() {
|
||||
try {
|
||||
that->mark_finished_with_result(f_());
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif // defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -3929,7 +3887,11 @@ namespace detail {
|
||||
////////////////////////////////
|
||||
// make_ready_future
|
||||
////////////////////////////////
|
||||
template <typename T>
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <int = 0, int..., class T>
|
||||
#else
|
||||
template <class T>
|
||||
#endif
|
||||
BOOST_THREAD_FUTURE<typename decay<T>::type> make_ready_future(BOOST_THREAD_FWD_REF(T) value) {
|
||||
typedef typename decay<T>::type future_value_type;
|
||||
promise<future_value_type> p;
|
||||
@@ -3937,6 +3899,35 @@ namespace detail {
|
||||
return BOOST_THREAD_MAKE_RV_REF(p.get_future());
|
||||
}
|
||||
|
||||
// explicit overloads
|
||||
template <class T>
|
||||
BOOST_THREAD_FUTURE<T> make_ready_future(typename remove_reference<T>::type & x)
|
||||
{
|
||||
promise<T> p;
|
||||
p.set_value(x);
|
||||
return p.get_future();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
BOOST_THREAD_FUTURE<T> make_ready_future(BOOST_THREAD_FWD_REF(typename remove_reference<T>::type) x)
|
||||
{
|
||||
promise<T> p;
|
||||
p.set_value(forward<typename remove_reference<T>::type>(x));
|
||||
return p.get_future();
|
||||
}
|
||||
|
||||
// variadic overload
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <class T, class ...Args>
|
||||
BOOST_THREAD_FUTURE<T> make_ready_future(Args&&... args)
|
||||
{
|
||||
promise<T> p;
|
||||
p.emplace(forward<Args>(args)...);
|
||||
return p.get_future();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, typename T1>
|
||||
BOOST_THREAD_FUTURE<T> make_ready_no_decay_future(T1 value) {
|
||||
typedef T future_value_type;
|
||||
@@ -4052,10 +4043,6 @@ namespace detail
|
||||
static void run(future_async_continuation_shared_state* that) {
|
||||
try {
|
||||
that->mark_finished_with_result(that->continuation(boost::move(that->parent)));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4086,10 +4073,6 @@ namespace detail
|
||||
try {
|
||||
that->continuation(boost::move(that->parent));
|
||||
that->mark_finished_with_result();
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4135,10 +4118,6 @@ namespace detail
|
||||
static void run(future_executor_continuation_shared_state* that) {
|
||||
try {
|
||||
that->mark_finished_with_result(that->continuation(boost::move(that->parent)));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4172,10 +4151,6 @@ namespace detail
|
||||
try {
|
||||
that->continuation(boost::move(that->parent));
|
||||
that->mark_finished_with_result();
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4210,10 +4185,6 @@ namespace detail
|
||||
static void run(shared_future_async_continuation_shared_state* that) {
|
||||
try {
|
||||
that->mark_finished_with_result(that->continuation(that->parent));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4244,10 +4215,6 @@ namespace detail
|
||||
try {
|
||||
that->continuation(that->parent);
|
||||
that->mark_finished_with_result();
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4285,10 +4252,6 @@ namespace detail
|
||||
static void run(shared_future_executor_continuation_shared_state* that) {
|
||||
try {
|
||||
that->mark_finished_with_result(that->continuation(that->parent));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4321,10 +4284,6 @@ namespace detail
|
||||
try {
|
||||
that->continuation(that->parent);
|
||||
that->mark_finished_with_result();
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4811,10 +4770,6 @@ namespace detail
|
||||
try {
|
||||
boost::wait_for_all(that->vec_.begin(), that->vec_.end());
|
||||
that->mark_finished_with_result(boost::move(that->vec_));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4885,10 +4840,6 @@ namespace detail
|
||||
try {
|
||||
boost::wait_for_any(that->vec_.begin(), that->vec_.end());
|
||||
that->mark_finished_with_result(boost::move(that->vec_));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -4993,10 +4944,6 @@ namespace detail
|
||||
that->wait_for_all(Index());
|
||||
|
||||
that->mark_finished_with_result(boost::move(that->tup_));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
@@ -5067,10 +5014,6 @@ namespace detail
|
||||
that->wait_for_any(Index());
|
||||
|
||||
that->mark_finished_with_result(boost::move(that->tup_));
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
} catch(thread_interrupted& ) {
|
||||
that->mark_interrupted_finish();
|
||||
#endif
|
||||
} catch(...) {
|
||||
that->mark_exceptional_finish();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace boost
|
||||
/// Effect: Decrement the count. Unlocks the lock and notify anyone waiting if we reached zero.
|
||||
/// Returns: true if count_ reached the value 0.
|
||||
/// @ThreadSafe ensured by the @c lk parameter
|
||||
bool count_down(unique_lock<mutex> &lk)
|
||||
bool count_down(unique_lock<mutex> &)
|
||||
/// pre_condition (count_ > 0)
|
||||
{
|
||||
BOOST_ASSERT(count_ > 0);
|
||||
|
||||
@@ -349,6 +349,7 @@ rule thread-compile ( sources : reqs * : name )
|
||||
[ thread-run2-noit ./sync/futures/promise/set_rvalue_pass.cpp : promise__set_rvalue_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/set_value_const_pass.cpp : promise__set_value_const_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/set_value_void_pass.cpp : promise__set_value_void_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/emplace_pass.cpp : promise__emplace_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/use_allocator_pass.cpp : promise__use_allocator_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/set_exception_at_thread_exit_pass.cpp : promise__set_exception_at_thread_exit_p ]
|
||||
[ thread-run2-noit ./sync/futures/promise/set_lvalue_at_thread_exit_pass.cpp : promise__set_lvalue_at_thread_exit_p ]
|
||||
@@ -357,6 +358,12 @@ rule thread-compile ( sources : reqs * : name )
|
||||
[ thread-run2-noit ./sync/futures/promise/set_value_at_thread_exit_void_pass.cpp : promise__set_value_at_thread_exit_void_p ]
|
||||
;
|
||||
|
||||
#explicit ts_make_ready_future ;
|
||||
test-suite ts_make_ready_future
|
||||
:
|
||||
[ thread-run2-noit ./sync/futures/make_ready_future_pass.cpp : make_ready_future_p ]
|
||||
;
|
||||
|
||||
#explicit ts_future ;
|
||||
test-suite ts_future
|
||||
:
|
||||
@@ -784,7 +791,7 @@ rule thread-compile ( sources : reqs * : name )
|
||||
[ thread-run2 ../example/parallel_accumulate.cpp : ex_parallel_accumulate ]
|
||||
[ thread-run2 ../example/parallel_quick_sort.cpp : ex_parallel_quick_sort ]
|
||||
[ thread-run2 ../example/with_lock_guard.cpp : ex_with_lock_guard ]
|
||||
|
||||
[ thread-run2 ../example/fib_task_region.cpp : ex_fib_task_region ]
|
||||
;
|
||||
|
||||
#explicit ts_shared_upwards ;
|
||||
@@ -902,6 +909,19 @@ rule thread-compile ( sources : reqs * : name )
|
||||
#[ thread-run ../example/perf_condition_variable.cpp ]
|
||||
#[ thread-run ../example/perf_shared_mutex.cpp ]
|
||||
;
|
||||
|
||||
|
||||
#explicit ts_exception_list ;
|
||||
test-suite ts_exception_list
|
||||
:
|
||||
[ thread-run2-noit ./experimental/parallel/v1/exception_list_pass.cpp : exception_list_p ]
|
||||
;
|
||||
|
||||
#explicit ts_task_region ;
|
||||
test-suite ts_task_region
|
||||
:
|
||||
[ thread-run2-noit ./experimental/parallel/v2/task_region_pass.cpp : task_region_p ]
|
||||
;
|
||||
|
||||
explicit ts_ ;
|
||||
test-suite ts_
|
||||
|
||||
23
test/experimental/parallel/v1/exception_list_pass.cpp
Normal file
23
test/experimental/parallel/v1/exception_list_pass.cpp
Normal 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();
|
||||
}
|
||||
293
test/experimental/parallel/v2/task_region_pass.cpp
Normal file
293
test/experimental/parallel/v2/task_region_pass.cpp
Normal file
@@ -0,0 +1,293 @@
|
||||
// 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
|
||||
#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_RANGE_BASED_FOR
|
||||
using boost::experimental::parallel::v2::task_region;
|
||||
using boost::experimental::parallel::v2::task_region_handle;
|
||||
using boost::experimental::parallel::v1::exception_list;
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_NO_CXX11_LAMBDAS
|
||||
|
||||
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;
|
||||
});
|
||||
BOOST_TEST(false);
|
||||
});
|
||||
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);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if ! defined BOOST_NO_CXX11_LAMBDAS
|
||||
run_no_exception();
|
||||
run_no_exception_wait();
|
||||
run_exception();
|
||||
run_exception_1();
|
||||
run_nested_exception();
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
157
test/sync/futures/make_ready_future_pass.cpp
Normal file
157
test/sync/futures/make_ready_future_pass.cpp
Normal 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 Ôboost::future<boost::rv<movable2> >Õ to non-scalar type Ôboost::future<movable2>Õ 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();
|
||||
}
|
||||
|
||||
207
test/sync/futures/promise/emplace_pass.cpp
Normal file
207
test/sync/futures/promise/emplace_pass.cpp
Normal 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user