Is ACE reactor timer managment thread safe?

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 that 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.