Robert Szokovacs wrote:
On Wednesday 22 April 2009 10:33:49 Raphael Coeffic wrote:

Hi,

I would not mess with signals and threads, as this is not very safe. I
had some issues with SEMS reacting differently on different linux
flavors because of a different behavior of signals related with threads.

I didn't mean it like that, I just pressed ^C and noticed that sig_usr_un() gets called and it does some housekeeping before calling exit().

If you want to participate in the shutdown process, the easiest way is
to register your helper thread at the AmEventDispatcher
(::addEventQueue(...)).
All you have to do is inheritate your class from AmEventQueueInterface
(and of course implement the few virtual methods provided by this
interface). This way, you will receive an event
(AmSystemEvent::ServerShutdown) when the system is shut down. Please
remember to handle this event asynchronously, as the postEvent() method
would block the caller thread otherwise.

If I do it asynchronously, is it guaranteed that my stuff will finish?


Yes. All you have to do is to remove your helper thread from the AmEventDispatcher at last. A quick look at AmSessionContainer::on_stop() will convince you for sure ;-)

The only issue would be that you have to clean the memory as well. The memory for the sessions get cleaned by AmSessionContainer. In your case, you could use AmThreadWatcher (AmThread.h). It implements a garbage collector that deletes your instance as soon as it is stopped (+ some delay, because the garbage collector only runs every 10 seconds).


-Raphael.
br

Szo
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to