|This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.|
Exit a Photon program
void PtExit( int return_code );
This function is similar to exit(), except that PtExit() properly destroys all your application's widgets before exiting.
In a multithreaded application, a callback can call PtExit() in one thread while a second thread might be in the middle of an important operation, such as writing a file. To prevent the second thread from terminating early, call PtPreventExit() before starting the operation, and call PtAllowExit() when it's done.
|Instead of calling PtPreventExit() and PtAllowExit() directly, you're better off calling PtEnter() and PtLeave() with Pt_DELAY_EXIT set in the flags, because the Pt_DELAY_EXIT flag may not cause your application to lock up
in some situations where PtPreventExit() would. For a discussion of the difference between these functions and using Pt_DELAY_EXIT, see “Exiting a multithreaded program” in the Parallel Operations chapter of the Photon Programmer's Guide.
However, if you create a widget or add a Pt_CB_APP_EXIT callback inside a PtEnter(Pt_DELAY_EXIT) section, and another thread has already called PtExit(), there's no guarantee that the new widget will be destroyed, or the new callback called.
Before exiting, PtExit():
- Invokes all the callbacks in the Pt_CB_APP_EXIT list.
The callbacks in Pt_CB_APP_EXIT are called only once, even if PtExit() is called multiple times (for example by multiple threads, or recursively from a Pt_CB_APP_EXIT callback).
- Destroys all the application's widgets.
- Enters the delayed exit state. In this state, the function waits for the counter associated with the PtPreventExit() function and the Pt_DELAY_EXIT flag to reach zero, if it's not zero. If its value is nonzero, PtExit() unlocks the library using an equivalent of PtLeave(0) (notice that this will decrement the counter if the Pt_DELAY_EXIT flag is in effect for the calling thread) and waits until the counter reaches zero. If PtExit() is called again by another thread, that second call also unlocks the library and blocks until the first call terminates the process.
This function doesn't return.
|Signal handler||Not applicable|
exit() in the QNX Neutrino Library Reference