|
Boost : |
From: Steve Weber (steve.weber.junk_at_[hidden])
Date: 2007-03-26 14:09:15
Im kinda noob only 2 years of c++
When joining two threads using a recursive_mutex. The recursive_mutex is
not shared resulting in dead lock.
Is this a "bug" or am i missing something.
also what would be a good solution to this?
Example code of my problem.
----------------------------------------------------------------------
class Test{
public:
boost::recursive_mutex m_mutex;
boost::thread* m_thread;
bool m_endThread;
// start thread
Test() : m_endThread( false ) {
m_thread = new boost::thread( boost::bind( &Test::threaded, this )
);
}
// cleanup
virtual ~Test() {
boost::recursive_mutex::scoped_lock l( m_mutex );
m_endThread = true;
m_thread->join(); //< DEAD LOCK
delete m_thread;
}
// the thread that will block
void threaded() {
for (;;){
boost::recursive_mutex::scoped_lock l( m_mutex ); //< DEAD LOCK
if ( m_endThread ) return;
}
}
};
int main() {
Test t;
}
----------------------------------------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk