0

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
rahul
  • 59
  • 1
  • 8
  • Nothing specific to boost and asio, use modern C++ lambda function instead of old bind – Jean Davy Sep 14 '20 at 16:58
  • @JeanDavy I tried with lambda, however I observed it too failed few times, not sure what is going wrong. – rahul Sep 15 '20 at 02:47
  • So focus on what is going wrong, the problem is not lambda itself. – Jean Davy Sep 15 '20 at 06:07
  • I found that post is successfully working, however handler never getting executed. somehow ioc not executing handlers...looking into it more. – rahul Sep 18 '20 at 02:14

1 Answers1

0

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

rahul
  • 59
  • 1
  • 8