
Here is an example that demonstrates the problem: //TestBoostTimeSentinel.cpp: #include "Test.h" void main() { for (int i=0; i<100; i++) { Test* a = new Test(); delete a; } } //Test.h: #include <boost/thread/condition_variable.hpp> #include <queue> class Test { public: Test(void); ~Test(void); private: void start(); boost::shared_ptr<boost::thread> _executorThread; mutable boost::mutex _mutex; std::priority_queue<int, std::string, std::less<int> > _prioQueue; boost::condition_variable _emptyQueueCondition; }; //Test.cpp: #include "Test.h" Test::Test(void) : _executorThread(boost::shared_ptr<boost::thread>(new boost::thread(&Test::start, this))) {} Test::~Test(void) {} void Test::start() { while (true) { boost::mutex::scoped_lock lock(_mutex); while (_prioQueue.empty()) { _emptyQueueCondition.wait(lock); } } } I use a for-loop because the problem doesnt occur every time. 2009/3/30 Anthony Williams <anthony.ajw@gmail.com>
Filip Klasson <filkl784@student.liu.se> writes:
Hi,
I get Assertion failed timed_lock(::boost::detail::get_system_time_sentinel()), file c:\boost\thread\win32\basic_timed_mutex.hpp, line 64.
Code in basic_timed_mutex.hpp: void lock() {
BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel())); //Line 64 }
That really is bizarre. Can you show a minimal example that demonstrates the problem?
Here is my code, i have marked where Assertion failed happends.
boost::mutex::scoped_lock lock(_mutex); while(_queue.empty()) { _condition.wait(lock); } //Assertion failed happends here. //Another thread is signaling the condition variable when an element is added to the _queue.
What is the lifetime of the various elements _mutex, _condition and _queue? Is it possible that they have been destroyed by another thread?
Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost