mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-21 02:52:18 +00:00
63 lines
1.2 KiB
Plaintext
63 lines
1.2 KiB
Plaintext
[/
|
|
Copyright Oliver Kowalke 2009.
|
|
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:own_thread Execute in Current Thread]
|
|
|
|
[heading Synopsis]
|
|
|
|
__own_thread__ executes the task in the current thread (synchronous execution).
|
|
|
|
long fibonacci( long n)
|
|
{
|
|
if ( n == 0) return 0;
|
|
if ( n == 1) return 1;
|
|
long k1( 1), k2( 0);
|
|
for ( int i( 2); i <= n; ++i)
|
|
{
|
|
long tmp( k1);
|
|
k1 = k1 + k2;
|
|
k2 = tmp;
|
|
}
|
|
return k1;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
boost::task::task< long > t( fibonacci, 10);
|
|
|
|
boost::task::handle< long > h(
|
|
boost::task::async(
|
|
boost::move( t),
|
|
boost::task::own_thread() ) );
|
|
|
|
std::cout << "fibonacci(10) == " << h.get() << std::endl;
|
|
}
|
|
|
|
|
|
[section:own_thread Class `own_thread`]
|
|
|
|
#include <boost/task/async.hpp>
|
|
|
|
struct own_thread
|
|
{
|
|
template< typename R >
|
|
handle< R > operator()( task< R > t);
|
|
};
|
|
|
|
[section `template< typename R > handle< R > operator()( task< R > t)`]
|
|
[variablelist
|
|
[[Effects:] [moves task in the current thread an returns an handle associated with the task]]
|
|
[[Throws:] [Nothing]]
|
|
]
|
|
[endsect]
|
|
|
|
[endsect]
|
|
|
|
[endsect]
|
|
|