This forum has been archived. Please start a new discussion on GitHub.

Safely removing a servant


We came across a problem in removing a servant from the object adapter. I have a servant that I want to destroy. I try to:
a) remove it from the adapter [with adapter->remove(id)], then
b) call its destructor.

The problem is that it seems to be possible for a remote call to still be in progress when (a) has completed, such that there is a threading issue between the ongoing remote call and the destructor in (b).

How can I do this safely? I can't see a way out of this, since it doesn't seem to be possible to guarantee that the adapter doesn't have a remote call which it's just about to begin, despite the object having been removed. Is there a solution?

Thanks in advance,



  • benoit
    benoit Rennes, France
    Hi Alex,

    By destructor, are you referring to the C++ destructor? If that's the case, it shouldn't be invoked until all the dispatched calls on the servant are finished as the dispatching increments the reference count of the servant.

    Otherwise, if by destructor you meant a destroy method that you implement and which is called after the servant is removed from the object adapter, you will need to add synchronization to this method and set a _destroy flag to prevent other calls on the servant. See Michi's newsletter article "The Samsara of Objects: Life Cycle Operations" for more information on this.

  • Hi Benoit,

    The article answered my questions, thanks very much for the help.