I have a GUI program with wxwidgets. When a Button is clicked, a new thread is supposed to start and run, so that it doesn't block the UI.
From the thread, a function is called that takes a callback function as argument.
When I run the program without threading (hence blocked UI), there's no Problem.
But when I use boost:thread
as i do in the code below, the thread does not run properly.
The program stops in the callback function CallBack()
when it tries to set the member variable m_intValue
. This is succesful without a seperate thread, but hangs when I put it in a separate thread.
Any thoughts? I have tried to simplify the code so that it's more readable. Please excuse if it won't compile like this. I'm just asking, maybe someone knows right away where the problem is!
Code
class MainFrame : public wxFrame
{
protected:
boost:thread m_workerThread;
m_intValue;
WorkerThread(Foo& afoo, Bar& aBar)
{
afoo.doSmth(aBar, boost::bind(&MainFrame::CallBack, this, _1, _2, _3)
}
void OnButtonClick()
{
Foo oFoo;
Bar oBar;
m_workerThread = boost::thread(&MainFrame::WorkerThread, this, boost::ref(oFoo), boost::ref(oBar));
}
void CallBack(int arg, int arg1, int arg2 )
{
m_intValue = arg;
}
};