Reactor::remove_handler的疑问?
有一个反应堆事件检测,多路分离,分派的线程.A.
另有一个线程B. 现有一个ACE_Connector的对象,假设其指针p指向它 (在堆中分配),并已经注册到A线程的运行的reactor中. 如果在B线程调用p->close( )来关闭该连接器.会不会出现多线程方面的问题, 我看了一下close的实现代码. 大致如下:
SVC_HANDLER *svc_handler = 0;
// Make sure that we haven't already initialized the Svc_Handler.
if (this->svc_handler_)
{
// Exclusive access to the Reactor.
ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->reactor ()->lock (), 0);
// Double check.
if (this->svc_handler_)
{
// Remember the Svc_Handler.
svc_handler = this->svc_handler_;
// Remove from Reactor.
this->reactor ()->remove_handler
(this->svc_handler_->get_handle (),
ACE_Event_Handler::ALL_EVENTS_MASK);
//将触发handle_close,在handle_close中delete this; 问题是,这个是通过B线程调用的,而此时如果A正分派一个连接完成事件到handle_output挂钩函数(异步连接方式),会不会出现问题, 如何解决? (当然,动态分配的连接器对象可以在反应堆关闭时由反应堆释放空间. ), 是不是remove_handler函数都只能在reactor运行的线程中调用?
// Cancel timer.
this->reactor ()->cancel_timer
(this->timer_id (), 0, 0);
// Remove this handle from the set of non-blocking handles
// in the Connector.
this->connector_.non_blocking_handles ().clr_bit
(this->svc_handler_->get_handle ());
// We are done. Don't initialize the Svc_Handler again.
this->svc_handler_ = 0;
}
}