|
Boost Users : |
Subject: Re: [Boost-users] Threads and virtual functions
From: Igor R (boost.lists_at_[hidden])
Date: 2011-07-07 02:52:53
> class A{
> public:
> Â Â Â Â A();
> Â Â Â Â ~A();
> Â Â Â Â void Run();
> Â Â Â Â void ThreadA();
> Â Â Â Â virtual void HandleSomething();
> };
>
> void A::HandleSomething()
> {
>
> }
>
> void A::ThreadA()
> {
> Â Â Â Â if(condition)
> Â Â Â Â {
> Â Â Â Â Â Â Â HandleSomething();
> Â Â Â Â }
> }
>
> void A::Run()
> {
> Â Â Â Â boost::thread thread(&A::ThreadA,this);
> }
>
> This is my base class. As you can see the thread calls the virtual function
> when the condition becomes true. I use the virtual function in my derived
> class so everytime the condition becomes true the function HandleSomething()
> should do something. So far, so good but when I try to change some variables
> in the derived class the program crashes without any warning or error
> message. I use the latest Ubuntu version with GCC 4.5.3 and boost 1.46.1.
Do you call the virtual function in a constructor?
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