Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/Exit.3 @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 6.2 KB
Line 
1'\"
2'\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: Exit.3,v 1.6 2003/09/29 21:47:38 dkf Exp $
8'\"
9.so man.macros
10.TH Tcl_Exit 3 8.5 Tcl "Tcl Library Procedures"
11.BS
12.SH NAME
13Tcl_Exit, Tcl_Finalize, Tcl_CreateExitHandler, Tcl_DeleteExitHandler, Tcl_ExitThread, Tcl_FinalizeThread, Tcl_CreateThreadExitHandler, Tcl_DeleteThreadExitHandler, Tcl_SetExitProc \- end the application or thread (and invoke exit handlers)
14.SH SYNOPSIS
15.nf
16\fB#include <tcl.h>\fR
17.sp
18\fBTcl_Exit\fR(\fIstatus\fR)
19.sp
20\fBTcl_Finalize\fR()
21.sp
22\fBTcl_CreateExitHandler\fR(\fIproc, clientData\fR)
23.sp
24\fBTcl_DeleteExitHandler\fR(\fIproc, clientData\fR)
25.sp
26\fBTcl_ExitThread\fR(\fIstatus\fR)
27.sp
28\fBTcl_FinalizeThread\fR()
29.sp
30\fBTcl_CreateThreadExitHandler\fR(\fIproc, clientData\fR)
31.sp
32\fBTcl_DeleteThreadExitHandler\fR(\fIproc, clientData\fR)
33.sp
34.VS 8.5
35Tcl_ExitProc *
36\fBTcl_SetExitProc\fR(\fIproc\fR)
37.VE 8.5
38.SH ARGUMENTS
39.AS Tcl_ExitProc clientData
40.AP int status  in
41Provides information about why the application or thread exited.
42Exact meaning may
43be platform-specific.  0 usually means a normal exit, any nonzero value
44usually means that an error occurred.
45.AP Tcl_ExitProc *proc in
46Procedure to invoke before exiting application, or (for
47\fBTcl_SetExitProc\fR) NULL to uninstall the current application exit
48procedure.
49.AP ClientData clientData in
50Arbitrary one-word value to pass to \fIproc\fR.
51.BE
52
53.SH DESCRIPTION
54.PP
55The procedures described here provide a graceful mechanism to end the
56execution of a \fBTcl\fR application. Exit handlers are invoked to cleanup the
57application's state before ending the execution of \fBTcl\fR code.
58.PP
59Invoke \fBTcl_Exit\fR to end a \fBTcl\fR application and to exit from this
60process. This procedure is invoked by the \fBexit\fR command, and can be
61invoked anyplace else to terminate the application.
62No-one should ever invoke the \fBexit\fR system procedure directly;  always
63invoke \fBTcl_Exit\fR instead, so that it can invoke exit handlers.
64Note that if other code invokes \fBexit\fR system procedure directly, or
65otherwise causes the application to terminate without calling
66\fBTcl_Exit\fR, the exit handlers will not be run.
67\fBTcl_Exit\fR internally invokes the \fBexit\fR system call, thus it never
68returns control to its caller.
69.VS 8.5
70If an application exit handler has been installed (see
71\fBTcl_SetExitProc\fR), that handler is invoked with an argument
72consisting of the exit status (cast to ClientData); the application
73exit handler should not return control to Tcl.
74.VE 8.5
75.PP
76\fBTcl_Finalize\fR is similar to \fBTcl_Exit\fR except that it does not
77exit from the current process.
78It is useful for cleaning up when a process is finished using \fBTcl\fR but
79wishes to continue executing, and when \fBTcl\fR is used in a dynamically
80loaded extension that is about to be unloaded.
81On some systems \fBTcl\fR is automatically notified when it is being
82unloaded, and it calls \fBTcl_Finalize\fR internally; on these systems it
83not necessary for the caller to explicitly call \fBTcl_Finalize\fR.
84However, to ensure portability, your code should always invoke
85\fBTcl_Finalize\fR when \fBTcl\fR is being unloaded, to ensure that the
86code will work on all platforms. \fBTcl_Finalize\fR can be safely called
87more than once.
88.PP
89\fBTcl_ExitThread\fR is used to terminate the current thread and invoke
90per-thread exit handlers.  This finalization is done by
91\fBTcl_FinalizeThread\fR, which you can call if you just want to clean
92up per-thread state and invoke the thread exit handlers.
93\fBTcl_Finalize\fR calls \fBTcl_FinalizeThread\fR for the current
94thread automatically.
95.PP
96\fBTcl_CreateExitHandler\fR arranges for \fIproc\fR to be invoked
97by \fBTcl_Finalize\fR and \fBTcl_Exit\fR.
98\fBTcl_CreateThreadExitHandler\fR arranges for \fIproc\fR to be invoked
99by \fBTcl_FinalizeThread\fR and \fBTcl_ExitThread\fR.
100This provides a hook for cleanup operations such as flushing buffers
101and freeing global memory.
102\fIProc\fR should match the type \fBTcl_ExitProc\fR:
103.CS
104typedef void Tcl_ExitProc(ClientData \fIclientData\fR);
105.CE
106The \fIclientData\fR parameter to \fIproc\fR is a
107copy of the \fIclientData\fR argument given to
108\fBTcl_CreateExitHandler\fR or \fBTcl_CreateThreadExitHandler\fR when
109the callback
110was created.  Typically, \fIclientData\fR points to a data
111structure containing application-specific information about
112what to do in \fIproc\fR.
113.PP
114\fBTcl_DeleteExitHandler\fR and \fBTcl_DeleteThreadExitHandler\fR may be
115called to delete a
116previously-created exit handler.  It removes the handler
117indicated by \fIproc\fR and \fIclientData\fR so that no call
118to \fIproc\fR will be made.  If no such handler exists then
119\fBTcl_DeleteExitHandler\fR or \fBTcl_DeleteThreadExitHandler\fR does nothing.
120.PP
121.PP
122\fBTcl_Finalize\fR and \fBTcl_Exit\fR execute all registered exit handlers,
123in reverse order from the order in which they were registered.
124This matches the natural order in which extensions are loaded and unloaded;
125if extension \fBA\fR loads extension \fBB\fR, it usually
126unloads \fBB\fR before it itself is unloaded.
127If extension \fBA\fR registers its exit handlers before loading extension
128\fBB\fR, this ensures that any exit handlers for \fBB\fR will be executed
129before the exit handlers for \fBA\fR.
130.PP
131\fBTcl_Finalize\fR and \fBTcl_Exit\fR call \fBTcl_FinalizeThread\fR
132and the thread exit handlers \fIafter\fR
133the process-wide exit handlers.  This is because thread finalization shuts
134down the I/O channel system, so any attempt at I/O by the global exit
135handlers will vanish into the bitbucket.
136.PP
137.VS 8.5
138\fBTcl_SetExitProc\fR installs an application exit handler, returning
139the previously-installed application exit handler or NULL if no
140application handler was installed.  If an application exit handler is
141installed, that exit handler takes over complete responsibility for
142finalization of Tcl's subsystems via \fBTcl_Finalize\fR at an
143appropriate time.  The argument passed to \fIproc\fR when it is
144invoked will be the exit status code (as passed to \fBTcl_Exit\fR)
145cast to a ClientData value.
146.VE 8.5
147
148.SH KEYWORDS
149callback, cleanup, dynamic loading, end application, exit, unloading, thread
Note: See TracBrowser for help on using the repository browser.