1
我的辅助线程侦听通道rabbit,并希望在我调用stopListen()方法时从主线程中删除它。C++杀死等待std ::线程
void PFClient::startListen()
{
this->stop = false;
this-> t = thread(&PFClient::callback,this);
}
void PFClient::callback()
{
PFAPIResponse* response;
char * temp;
while (!this->stop)
{
try
{
std::string receiver_data = "";
//std::wcout << L"[Callback] oczekiwanie na wiadomość !" << endl;
receiver_data = this->channel->BasicConsumeMessage()->Message()->Body();
temp = &receiver_data[0];
... some operation with received data
void PFClient::stopListen()
{
this->stop = true;
}
信号量无法正常工作,因为它只能在下一次收到的消息后才起作用。 我尝试detach(),terminate()但不工作。 我该如何残忍地杀死这个过程?
你真的应该避免杀死它(资源泄漏等) – deviantfan
你会用* NO-阻止*接收功能?每个体面的图书馆都应该有* block_for *功能 –
@deviantfan我知道,但是如果我想如何做到这一点? – Jakooop