开发者

Is ACE reactor timer managment thread safe?

开发者 https://www.devze.com 2022-12-16 15:48 出处:网络
I have a module that manages timers in my aplication. This class has basibly three functions: Instance of ACE_Reactor is used internally by the module to manage the timers.

I have a module that manages timers in my aplication. This class has basibly three functions:

Instance of ACE_Reactor is used internally by the module to manage the timers.

  • schedule timer - calls ACE_Reactor::schedule_timer(). One of the arguments is a callback, called upon timer experation.
  • cancel timer - calls ACE_Reactor::cancel_timer()

The reactor executed in private timer of execution, so schedule/cancel and timeout callback are executed in different threads.

ACE_Reactor::schedule_timer() receives a heap allocatec structure ( arg argument).

This structure later deleted when canceling timer or when timeout handler is called. But since cancel and timeout handler are executed in different threads it looks like there's cases t开发者_JS百科hat the structure is deleted twice.

Isn't it responsibility of reactor to ensure that timer is canceled when timeout handler is called?


AFAIK such a case is definitely possible with ACE_TP_Reactor. Using the TP-reactor, the timeouts are not synchronized on the same thread. I.e. a timeout can occur when you are in a midst of doing a handle_input in some other thread. You will have to synchronize the events. A clean way to do it would be to adapt the ACE_Event_Handler interface for synchronization.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号