How to bind parameter with Boost asio io_context post?

855 views Asked by At

I am trying to post data to io_context, if I bind post with newdata method (with no parameter) it get called, however if I pass any parameter it failed to call newdata method.

std::shared_ptr< boost::asio::io_context >ioc = std::make_shared<boost::asio::io_context>();
 :
ioc->post(boost::bind(&myclass::newdata, this));  /// <-- this get called
ioc->post(boost::bind(&myclass::newdata, this, 1));  /// <-- this get failed, no compile time error

// I tried with boost::function, but it failed to compile

boost::function<void(int>)> p(boost::bind(&myclass::newdata, this, _1));
ioc->post(p(1));   // <-- compile time error
1

There are 1 answers

0
rahul On

The thread which is calling ioc->post() doesn't have ioc->run(), as soon I put the same it worked.