[thread] boost::async and launch::deferred - Runtime Error + PATCH
Hi Vicente, hi all, The following code snippet throws an exception at runtime boost::future<int> f1 = boost::async( boost::launch::deferred, []() { return 123; }); int x= f1.get(); //exception thrown I am using Boost Trunk revision 83512 I attached a patch, but I'm not sure that's correct, I had no time to see the full future.hpp code I noticed that according to N3558, the future::is_ready() function should be called "ready". http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3558.pdf What do you think? Thanks and regards, Fernando.
Le 22/03/13 00:17, Fernando Pelliccioni a écrit :
Hi Vicente, hi all,
The following code snippet throws an exception at runtime
boost::future<int> f1 = boost::async( boost::launch::deferred, []() { return 123; });
int x= f1.get();//exception thrown
I am using Boost Trunk revision 83512 I attached a patch, but I'm not sure that's correct, I had no time to see the full future.hpp code
The current implementation needs some C++11 features (sorry I have not had the time to get rid of these features). Your patch lets me think that either you are not defining BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK or BOOST_THREAD_PROVIDES_VARIADIC_THREAD is not defined for your compiler. Could you confirm? detail/config.h defines #if ! defined(BOOST_NO_SFINAE_EXPR) && \ ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ ! defined(BOOST_NO_CXX11_DECLTYPE) && \ ! defined(BOOST_NO_CXX11_DECLTYPE_N3276) && \ ! defined(BOOST_NO_CXX11_AUTO) && \ ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ ! defined(BOOST_NO_CXX11_HDR_TUPLE) #define BOOST_THREAD_PROVIDES_VARIADIC_THREAD #endif Please, let me know if this was not clear in the documentation.
I noticed that according to N3558, the future::is_ready() function should be called "ready". http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3558.pdf
What do you think?
I could add it as well as make_ready_future. Best, Vicente
On Thu, Mar 21, 2013 at 9:17 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
Le 22/03/13 00:17, Fernando Pelliccioni a écrit :
Hi Vicente, hi all,
The following code snippet throws an exception at runtime
boost::future<int> f1 = boost::async( boost::launch::deferred, []() { return 123; });
int x= f1.get(); //exception thrown
I am using Boost Trunk revision 83512 I attached a patch, but I'm not sure that's correct, I had no time to see the full future.hpp code
The current implementation needs some C++11 features (sorry I have not had the time to get rid of these features). Your patch lets me think that either you are not defining BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK or BOOST_THREAD_PROVIDES_VARIADIC_THREAD is not defined for your compiler. Could you confirm?
detail/config.h defines
#if ! defined(BOOST_NO_SFINAE_EXPR) && \ ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ ! defined(BOOST_NO_CXX11_DECLTYPE) && \ ! defined(BOOST_NO_CXX11_DECLTYPE_N3276) && \ ! defined(BOOST_NO_CXX11_AUTO) && \ ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ ! defined(BOOST_NO_CXX11_HDR_TUPLE)
#define BOOST_THREAD_PROVIDES_VARIADIC_THREAD #endif
I am using MSVC10 at the moment, no support for variadic templates. That is, BOOST_THREAD_PROVIDES_VARIADIC_THREAD is not defined In this case, is it necessary that I define BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK?... ...Or support for C++11 (variadics templates) is exclusive?
Please, let me know if this was not clear in the documentation.
I have not seen these requirements in the documentation, but I'm not sure if the documentation is clear or not. Perhaps I omitted to read it.
I noticed that according to N3558, the future::is_ready() function should be called "ready". http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3558.pdf
What do you think?
I could add it as well as make_ready_future.
On the other hand, I'm looking to do something like boost::future<string> f1 = boost::async( boost::launch::async, []() { return someSlowWork(); // (1) executed on other thread }); // int return is a workaround. A compilation error occurs if I use future<void> boost::future<int> f2 = f1.then( boost::launch::deferred [this]( boost::future<string> & f) -> int { string result = f.get(); updateGuiWidget( result ); return 1; }); I use launch::deferred in the continuation because I need to execute it on the GUI Thread, but is executed on the same thread as (1) I'm not clear if the behavior of boost::future:: then is correct, according to N3558. Using schedullers and executors, I could select the thread of the continuation, but I don't undestand the purpose of launch polity on "then" function.
Best, Vicente
Regards, Fernando.
participants (2)
-
Fernando Pelliccioni
-
Vicente J. Botet Escriba