|
Boost Users : |
Subject: Re: [Boost-users] [thread] : pause/resume thread
From: bit bit (g_rambot_at_[hidden])
Date: 2011-04-15 09:22:51
remove fptr(this);
You call qthread's Execute() from your main thread and you are waiting on a condition variable.
> To: boost-users_at_[hidden]
> From: Viatcheslav.Sysoltsev_at_[hidden]
> Date: Fri, 15 Apr 2011 15:18:06 +0200
> Subject: Re: [Boost-users] [thread] : pause/resume thread
>
> > Hi All, I have just started learning boost. I want my thread to support
> > following functions
> > Pause();
> > Resume();
> > Stop();.
> > I have come up with following code, which ends up as dead lock. Can some
> > one
> > please guide me as how to achieve the desired functionality.
> > Would really appreciate any help.
> > Thanks.
> > Kaz
> > class qthread
> > {
> > public:
> > boost::thread* mThread;
> > boost::condition_variable mCond;
> > boost::mutex mMutex;
> > bool mExit;
> > qthread(): mExit(false)
> > {
> > // create function pointer to local Execute function
> > boost::function<void (qthread*)> fptr = &qthread::Execute;
> > fptr(this);
> you call Execute() here in the main thread
>
>
> > // pass on function pointer along with this reference to boost
> > thread
> > boost::thread th0( fptr, this);
> > // assign temp thread to local variable
> > mThread = &th0;
> > }
> and now your th0 is destroyed leaving invalid pointer. Strange, I thought
> gcc has already learned to warn about such stuff, but I don't get any
> warning with gcc 4.3.2 here even with -Wall
>
>
>
> > mCond.wait(lock); //<< DEAD LOCK
> It's not a dead lock, don't swear with so scary words ;). If you'd debug
> the program, you see you are still having only one thread by the time.
>
> -- Slava
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net