Exemple #1
0
void swap( promise< R > & l, promise< R > & r) noexcept {
    l.swap( r);
}
Exemple #2
0
        task< R > t( f, ctx1);
        callable ca( fn, boost::move( prom), ctx2);
        shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
        ctx1.reset( thrd);
        return t;
	}

	template< typename Fn >
	task< typename result_of< Fn() >::result_type >
    operator()( BOOST_RV_REF( Fn) fn)
	{
        typedef typename result_of< Fn() >::result_type  R;

		BOOST_ASSERT( ! this_task::runs_in_pool() );

        promise< R > prom;
        unique_future< R > f( prom.get_future() );
        context ctx1, ctx2;
        task< R > t( f, ctx1);
        callable ca( boost::move( fn), boost::move( prom), ctx2);
        shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
        ctx1.reset( thrd);
        return t;
	}
};

}}

#ifdef BOOST_HAS_ABI_HEADERS
#  include BOOST_ABI_SUFFIX
#endif
Exemple #3
0
void swap(promise<T>& lhs, promise<T>& rhs)
{
    lhs.swap(rhs);
}
Exemple #4
0
void foo(promise<unsigned int> p)
{
    sleep(1);
    p.set_value(42);
}
void work2(promise<int> prom) {
    printf("this is thread2\n");  //C++11的线程输出cout没有boost的好,还是会出现乱序,所以采用printf,有点不爽
    flag=2;
    prom.set_value(10);  //线程2设置了共享状态后,线程1才会被唤醒
    printf("thread2 exit\n");
}