怎样安全的退出Task中创建的各个线程?
Task中的线程都在getq处阻塞了,我怎样安全的退出他们?之前好像在什么地方看到过有,说是发一个什么消息,但有找不到了,所以再问一下。哪位知道的帮忙顶一下。 看看是不是这个virtual int ACE_Message_Queue<>::deactivate( void )
Deactivate the queue and wakeup all threads waiting on the queue so they can continue. No messages are removed from the queue, however. Any other operations called until the queue is activated again will immediately return -1 with <errno> == ESHUTDOWN. Returns WAS_INACTIVE if queue was inactive before the call and WAS_ACTIVE if queue was active before the call. 可以通过ACE_Message_Block::MB_STOP
ACE_Message_Block* lastMsg = new ACE_Message_Block(0, ACE_Message_Block::MB_STOP)
otherTask->putq(lastMsg);
otherTask在接收到的时候如下处理
int OtherTask::svc()
{
ACE_Message_Block* mb;
while(1)
{
getq(mb);
if(mb->get_tpye() == ACE_Message_Block::MB_STOP)
{
mb->release();
break; //退出这个永久限环)
}
else
{
handle_message(mb); //处理这条消息
}
return 0;
} 用test_cancel函数
页:
[1]