Modify

Ticket #4710 (closed Feature Requests: fixed)

Opened 4 years ago

Last modified 20 months ago

c++11 compliance: : Missing async()

Reported by: dave Owned by: viboes
Milestone: Boost 1.52.0 Component: thread
Version: Boost 1.44.0 Severity: Problem
Keywords: async standard Cc: viboes

Description

The lack of an async() call makes futures awfully cumbersome to use. I hacked up this nullary prototype for C++03. It's better than nothing!

#include <boost/thread.hpp>
#include <boost/utility/result_of.hpp>

template <class F>
boost::detail::thread_move_t<boost::unique_future<typename boost::result_of<F()>::type> >
async(F f)
{
    typedef typename boost::result_of<F()>::type R;
    boost::packaged_task<R> pt( f );
    
    typedef boost::unique_future<R> future;
    future ret = pt.get_future();
    boost::thread( boost::move(pt) ).detach();
    return boost::move(ret);
}

Attachments

Change History

comment:1 Changed 3 years ago by viboes

  • Type changed from Bugs to Feature Requests
  • Component changed from threads to thread

comment:2 Changed 2 years ago by viboes

  • Cc viboes added
  • Keywords async standard added

comment:3 Changed 2 years ago by anonymous

  • Summary changed from Missing async() to c++11 complicance: : Missing async()

comment:4 Changed 2 years ago by viboes

  • Summary changed from c++11 complicance: : Missing async() to c++11 compliance: : Missing async()

comment:5 Changed 2 years ago by viboes

  • Owner changed from anthonyw to viboes
  • Status changed from new to assigned

comment:6 Changed 20 months ago by viboes

  • Milestone changed from To Be Determined to Boost 1.52.0

comment:7 follow-up: ↓ 8 Changed 20 months ago by viboes

Add

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);

to conform with c++11.

comment:8 in reply to: ↑ 7 Changed 20 months ago by viboes

Replying to viboes:

Add

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);

to conform with c++11.

I will implement these prototypes later on.

For the time been, the minimal request has benn done.

comment:9 Changed 20 months ago by viboes

  • Status changed from assigned to closed
  • Resolution set to fixed

Merged from trunk [80450].

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.