Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] playing with boost::unique_futures
From: Conoscenza Silente (abruzzoforteegentile_at_[hidden])
Date: 2010-03-11 18:13:02


Sorry for this question. I read the forum policy and I addressed this mail
to boost-user mailing list.

HOn Thu, Mar 11, 2010 at 7:06 PM, Conoscenza Silente <
abruzzoforteegentile_at_[hidden]> wrote:

> Hi all
> I am doing my first steps in using boost::unique_future and below the
> example of usage
> that arose my question.
> Looking at the C++0x I can see that you can create a future using
> std::async.
> If I understood correctly the good thing of it is that, based on some
> policy that I imaging to be related
> to number of core availables+other things, std::async will choice for you
> whether to run your functions
> in a specific thread, or using a ThreadPool or other available resources.
> With the code I did below, once I have 2 functions I am forced to use
> alwyas 2 threads.
> Do you know what are the alternatives in Boost/ Boost Thread and if right
> now there is/there
> will be an equivalent of std::async in Boost?
> Thanks
>
> int firstBigOne(){
> for( int i = 0; i < 3; i++ ){
> std::cout << "firstBigOne" << std::endl;
> boost::this_thread::sleep( boost::posix_time::milliseconds(200) );
> }
>
> return 10;
> }
>
>
> int secondBigOne(){
> for( int i = 0; i < 4; i++ ){
> std::cout << "secondBigONe" << std::endl;
> boost::this_thread::sleep( boost::posix_time::milliseconds(200) );
> }
> return 20;
> }
>
>
> void TestC(){
> try{
> boost::packaged_task<int> pt1(firstBigOne);
> boost::packaged_task<int> pt2(secondBigOne);
>
> boost::unique_future<int> f1=pt1.get_future();
> boost::unique_future<int> f2=pt2.get_future();
>
> boost::thread t1( boost::move( pt1 ));
> boost::thread t2( boost::move( pt2 ));
>
>



Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk