Advertisement
SRD

thread

SRD
Dec 10th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. I have a boost ASIO deadline timer in a boost thread and I'm trying to cancel the timer from the main thread.
  2.  
  3. boost::asio::io_service timer_service;
  4. boost::asio::deadline_timer timer(timer_service);
  5.  
  6. std::unique_ptr<boost::thread> m_thread;
  7.  
  8. // ...
  9. timer_service.reset();
  10. timer.expires_from_now(boost::posix_time::seconds(20));
  11. timer.async_wait(my_handler);
  12.  
  13. m_thread = unique_ptr<boost::thread>(new boost::thread(boost::bind(&boost::asio::io_service::run, &timer_service)));
  14.  
  15. From the main thread, I try to cancel it using this lambda, but getting the following compile error.
  16.  
  17. case CANCEL:
  18. {
  19. // ...
  20. timer.get_io_service().post([timer] { timer.cancel(); });
  21. break;
  22. }
  23.  
  24.  
  25. /boost/asio/detail/impl/task_io_service.hpp:56:6:
  26. error: 'void boost::asio::detail::task_io_service::post(Handler&) [with
  27. Handler = main(int, char**)::<lambda()>]', declared using local
  28. type 'main(int, char**)::<lambda()>', is used but never defined
  29. [-fpermissive]
  30. void task_io_service::post(Handler& handler)
  31. ^
  32.  
  33. Anyone see where I'm going wrong?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement