Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/thread.hpp>
- #include <boost/signals2.hpp>
- #include <boost/bind.hpp>
- boost::mutex theMutex;
- struct Obj
- {
- void fn1()
- {
- boost::lock_guard<boost::mutex> lock(theMutex);
- std::cout << (void *)this << "::fn1" << std::endl;
- }
- void fn2()
- {
- boost::lock_guard<boost::mutex> lock(theMutex);
- std::cout << (void *)this << "::fn2" << std::endl;
- }
- void fn3()
- {
- boost::lock_guard<boost::mutex> lock(theMutex);
- std::cout << (void *)this << "::fn3" << std::endl;
- }
- };
- struct Obj2
- {
- void operator()()
- {
- boost::lock_guard<boost::mutex> lock(theMutex);
- std::cout << (void *)this << ":Hello world" << std::endl;
- }
- };
- int main()
- {
- Obj o1, o2;
- Obj2 HW;
- boost::signals2::signal<void(void)> sig1, sig2;
- sig1.connect(HW);
- sig1.connect(boost::bind(&Obj::fn1, &o1));
- sig1.connect(boost::bind(&Obj::fn2, &o1));
- sig1.connect(boost::bind(&Obj::fn3, &o2));
- sig2.connect(boost::bind(&Obj::fn1, &o2));
- sig2.connect(boost::bind(&Obj::fn2, &o2));
- sig2.connect(boost::bind(&Obj::fn3, &o1));
- sig2.connect(HW);
- boost::thread t1(boost::ref(sig1)), t2(boost::ref(sig2));
- t1.join();
- t2.join();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement