boost::condition_variable cond;
boost::mutex mut;
void Database::run()
{
boost::unique_lock<boost::mutex> lock(mut);
while(true)
{
while(queries_queue.empty())
cond.wait(lock);
mysqlpp::Query* q = queries_queue.front(); // <<< CRASHES HERE <<<
q->execute();
queries_queue.pop_front();
}
}
void Database::Execute(mysqlpp::Query* q)
{
{
boost::lock_guard<boost::mutex> lock(mut);
queries_queue.push_back(q);
}
cond.notify_one();
}
run is executed by boost::thread. Execute is called by main program thread to queue an operation. However, it crashes after waking from the conditional wait.
What am I doing wrong?