Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class B
- {
- public:
- void operator()(){run();}
- void run();
- void shutdown();
- ~B();
- B();
- boost::thread *thr;
- bool shutdown_requested;
- };
- void B::shutdown()
- {
- shutdown_requested = true;
- if (thr != NULL)
- {
- thr->interrupt();
- thr->join(); // deadlock occurs here!
- delete thr;
- thr = NULL;
- }
- }
- B::~B()
- {
- shutdown();
- }
- B::B()
- {
- thr = new boost::thread(boost::ref(*this));
- }
- void B::run()
- {
- while (!shutdown_requested)
- {
- boost::xtime xt;
- boost::xtime_get(&xt, boost::TIME_UTC);
- xt.sec += 30;
- boost::this_thread::sleep(xt);
- }
- }
- int main()
- {
- B *b = new B;
- Sleep(5000);
- printf("deleting n");fflush(stdout);
- // b->shutdown();
- delete b;
- printf("donen");fflush(stdout);
- return 0;
- }
- int main()
- {
- B *b = new B;
- Sleep(5000);
- printf("deleting n");fflush(stdout);
- b->shutdown();
- delete b;
- printf("donen");fflush(stdout);
- return 0;
- }
Add Comment
Please, Sign In to add comment