Advertisement
Guest User

Untitled

a guest
Jun 11th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1.  
  2. #include <boost/asio/io_service.hpp>
  3. #include <boost/bind.hpp>
  4. #include <boost/thread.hpp>
  5. #include <boost/function.hpp>
  6. #include <boost/bind/protect.hpp>
  7.  
  8.  
  9. class MyClass
  10. {
  11. public:
  12.         MyClass():
  13.                 work_(ios_)
  14.         {
  15.         }
  16.  
  17.         ~MyClass() {}
  18.  
  19.         void func(int arg1, int arg2)
  20.         {
  21.                 std::cout << arg1 << " " << arg2 << std::endl;
  22.         }
  23.  
  24.         void test()
  25.         {
  26. #if 1
  27.                 boost::function<void()> f = boost::bind(&MyClass::func, this, 7, 42);
  28.                 boost::bind(&boost::asio::io_service::post, &ios_, f);
  29. #else
  30.                 boost::bind(&boost::asio::io_service::post, &ios_,
  31.                                 boost::protect(boost::bind(&MyClass::func, this, 7, 42)));
  32. #endif
  33.         }
  34.  
  35. private:
  36.         boost::asio::io_service ios_;
  37.         boost::asio::io_service::work work_;
  38. };
  39.  
  40.  
  41. int main(int argc, char **argv)
  42. {
  43.         MyClass obj;
  44.         obj.test();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement