我对 mutex / cond 等待类的这个简单包装器有疑问。我用它来保护已连接客户端的队列,并通知处于等待状态的线程有新的客户端连接,但应用程序因分段失败而崩溃
client_socket_fd = clients_for_threads_q.front();
仅在进行压力测试时(许多客户端已连接)
等待线程:
MUTEXCONDSIGNAL_for_workers.lock();
if ( clients_for_threads_q.empty() )
{
MUTEXCONDSIGNAL_for_workers.wait_signal();
}
client_socket_fd = clients_for_threads_q.front(); // CRASHED !!!!
clients_for_threads_q.pop();
MUTEXCONDSIGNAL_for_workers.unlock();
当然,clients_for_threads_q 在写作时受到保护
MUTEXCONDSIGNAL_for_workers.lock();
clients_for_threads_q.push (client_socket_fd);
MUTEXCONDSIGNAL_for_workers.send_signal();
MUTEXCONDSIGNAL_for_workers.unlock();