Skip to main content

Problem:

  • Product Name: VisiBroker for C
  • Product Version: 4.x or later
  • Product Component: ORB
  • Platform/OS Version: All

What are the effects of calling exit instead of shutdown?

1. What issues need to be considered if calling exit instead of ORB::shutdown() ?
2. On HPUX, will exit() call all the destructors?
3. Does shutdown internally create a new thread (p_thread)? Does this p_thread catch exceptions?

Resolution:

For 1 & 2)

The shutdown method:
static void shutdown(CORBA::Boolean wait_for_completion=0);
causes a previous invocation of the impl_is_ready method to return. All object adapters are shut down and associated memory is freed.

It is advisable for an application to always call ORB::shutdown() before exiting. This will allow the ORB to service the requests until all requests have been completed, deactivate the objects and cleanup the ORB, hence there will be a delay.

Calling _exit may not shutdown a system gracefully and may lead to other problems as any exit handlers are not called and the standard I/O buffers are not flushed. But the advantage is that it is faster.

exit calls only global destructors, and _exit terminates the program immediately without calling either local or global destructors.

Because destructors typically deallocate memory, "brute force" termination via exit or _exit causes problems in environments where resource recovery is not guaranteed by the operating system, such as in Windows or in an embedded system. In addition, if destructors are not called on program termination, memory debugging tools become less useful: they will report memory as still in use that otherwise would have been deallocated correctly.
 
Though VisiBroker installed an exit handler to call CORBA_ORB::shutdown(1UL) which will help to cleanup the ORB when exit is called. It is not advisable to rely on such an approach.

The C runtime would destruct or free all global data instances that are created by VisiBroker libraries before the exit handlers are triggered. The VisiBroker ORB shutdown/destroy code logic may need to depend on the these global data instances for its intended purpose. Since the memory has been freed by the C runtime, segmentation violation may occurred as the shutdown/destroy routine that used these memory are not awared of the freed instances.

Therefore, it is a good practice to explicitly call shutdown(1UL) to wait for completion before calling exit().

 
3) Yes. Some threads are started to deactivate objects. p_thread catches exceptions.

 

#Security
#VisiBroker