Hang in Boost thread join()
Added by Stas Magill about 13 years ago
Hi,
Has anyone else had any problems calling join() on Boost threads within a Wt app? It hangs for me every time. I've got the following very simple app that is created from WRun:
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
using namespace Wt;
class WtThreadApp : public WApplication
{
public:
WtThreadApp(const WEnvironment& env) :
WApplication(env)
{
setTitle("WtTest");
WPushButton* button= new WPushButton("Start", root());
button->clicked().connect(this, &WtThreadApp::startTest);
}
private:
boost::thread m_thread;
void startTest(void)
{
m_thread= boost::thread(boost::bind(&WtThreadApp::testThread, this));
cout << "Calling join\n";
m_thread.join();
cout << "Joined\n";
}
void testThread(void)
{
cout << "testThread started\n";
sleep(10);
cout << "testThread finished\n";
}
};
The output shows that the thread exits after the 10 second delay, but join() never completes. Can anyone suggest what might be going wrong?
Thanks.
Replies (3)
RE: Hang in Boost thread join() - Added by Wim Dumon about 13 years ago
Your code example works for me (windows 7). I don't see how Wt could interfere with that join().
Wim.
RE: Hang in Boost thread join() - Added by Stas Magill about 13 years ago
Thanks Wim.
Can you please let me know what version of Boost you are using?
Thanks.