Home Help Center

Ice AMI Callback Object Lifetime

eric.hilleric.hill Member Eric HillOrganization: Pioneer Balloon Co.Project: Internal Research
A call to an AMI method requires a callback object that implements the output side of the AMI request. Easy enough. The example on page 870 in the manual looks like this:
Demo::ModelPrx model = ...;
AMI_Model_interpolatePtr cb = new AMI_Model_interpolateI;
Demo::Grid grid;
initializeGrid(grid);
model->interpolate_async(cb, grid, 0.5);

The AMI_Model_interpolatePtr variable cb will fall out of scope at the end of the routine and be destroyed. Since the callback object pointer is passed into the _async request and it holds a pointer to the callback object instance, so will the callback object itself will be automatically destroyed by the Ice runtime after ice_response or ice_exception has been called?

In section 31.3.4 of the manual (Concurrency Issues), the first bullet point states that a callback object must not be used for multiple simultaneous invocations, and I'm guessing this is because one thread could destroy the callback object before the second one called it?

TIA

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Eric,

    The callback is ref-counted and gets deleted when the ref-count reaches 0, typically after ice_response() or ice_exception() has been called. You don't need to do anything special.

    Regarding concurrent use of a callback, the issue is not lifetime: the ref-counting of the callback is thread-safe. These callback objects are just not designed to handle multiple concurrent callbacks.

    Best regards,
    Bernard
  • eric.hilleric.hill Member Eric HillOrganization: Pioneer Balloon Co.Project: Internal Research
    Thanks.

    Thanks bernard!
Sign In or Register to comment.