Shutting Down Cleanly

Top  Previous  Next

In simple applications that have only one task linked with the full library, the server shuts down when this task exits. You can then run another application.

 

When an application contains more than one task linked with the full library, the server does not stop until they have all exited. However, it does not wait for tasks that are linked with the stand-alone library to exit.

 

The simple examples discussed up to now have not had to deal with errors. When an individual task detects an error, the following choices are available:


The offending task may simply exit. The rest of the application continues to operate, except that attempts to communicate with the failed task will hang. This is the simplest approach, and is recommended for new users. The drawback is that the host server will continue to run even when the application it is serving has failed, and may have to be shut down manually.

A failing task may orchestrate a controlled shutdown of all tasks linked with the full library, by sending messages to them. This approach is harder to design and implement, but results in the host server terminating cleanly.

A task may call the library function _server_terminate_now, which forces the host server to stop immediately. You should avoid this approach if possible, because other tasks will not be notified of the shutdown and may have important open files, which will not be closed properly.