Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/asio/io_service.hpp>
- #include <boost/bind.hpp>
- #include <boost/thread.hpp>
- #include <boost/function.hpp>
- #include <boost/bind/protect.hpp>
- class MyClass
- {
- public:
- MyClass():
- work_(ios_)
- {
- }
- ~MyClass() {}
- void func(int arg1, int arg2)
- {
- std::cout << arg1 << " " << arg2 << std::endl;
- }
- void test()
- {
- #if 1
- boost::function<void()> f = boost::bind(&MyClass::func, this, 7, 42);
- boost::bind(&boost::asio::io_service::post, &ios_, f);
- #else
- boost::bind(&boost::asio::io_service::post, &ios_,
- boost::protect(boost::bind(&MyClass::func, this, 7, 42)));
- #endif
- }
- private:
- boost::asio::io_service ios_;
- boost::asio::io_service::work work_;
- };
- int main(int argc, char **argv)
- {
- MyClass obj;
- obj.test();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement