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 |
---|
13 | Tcl_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 |
---|
35 | Tcl_ExitProc * |
---|
36 | \fBTcl_SetExitProc\fR(\fIproc\fR) |
---|
37 | .VE 8.5 |
---|
38 | .SH ARGUMENTS |
---|
39 | .AS Tcl_ExitProc clientData |
---|
40 | .AP int status in |
---|
41 | Provides information about why the application or thread exited. |
---|
42 | Exact meaning may |
---|
43 | be platform-specific. 0 usually means a normal exit, any nonzero value |
---|
44 | usually means that an error occurred. |
---|
45 | .AP Tcl_ExitProc *proc in |
---|
46 | Procedure to invoke before exiting application, or (for |
---|
47 | \fBTcl_SetExitProc\fR) NULL to uninstall the current application exit |
---|
48 | procedure. |
---|
49 | .AP ClientData clientData in |
---|
50 | Arbitrary one-word value to pass to \fIproc\fR. |
---|
51 | .BE |
---|
52 | |
---|
53 | .SH DESCRIPTION |
---|
54 | .PP |
---|
55 | The procedures described here provide a graceful mechanism to end the |
---|
56 | execution of a \fBTcl\fR application. Exit handlers are invoked to cleanup the |
---|
57 | application's state before ending the execution of \fBTcl\fR code. |
---|
58 | .PP |
---|
59 | Invoke \fBTcl_Exit\fR to end a \fBTcl\fR application and to exit from this |
---|
60 | process. This procedure is invoked by the \fBexit\fR command, and can be |
---|
61 | invoked anyplace else to terminate the application. |
---|
62 | No-one should ever invoke the \fBexit\fR system procedure directly; always |
---|
63 | invoke \fBTcl_Exit\fR instead, so that it can invoke exit handlers. |
---|
64 | Note that if other code invokes \fBexit\fR system procedure directly, or |
---|
65 | otherwise 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 |
---|
68 | returns control to its caller. |
---|
69 | .VS 8.5 |
---|
70 | If an application exit handler has been installed (see |
---|
71 | \fBTcl_SetExitProc\fR), that handler is invoked with an argument |
---|
72 | consisting of the exit status (cast to ClientData); the application |
---|
73 | exit 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 |
---|
77 | exit from the current process. |
---|
78 | It is useful for cleaning up when a process is finished using \fBTcl\fR but |
---|
79 | wishes to continue executing, and when \fBTcl\fR is used in a dynamically |
---|
80 | loaded extension that is about to be unloaded. |
---|
81 | On some systems \fBTcl\fR is automatically notified when it is being |
---|
82 | unloaded, and it calls \fBTcl_Finalize\fR internally; on these systems it |
---|
83 | not necessary for the caller to explicitly call \fBTcl_Finalize\fR. |
---|
84 | However, to ensure portability, your code should always invoke |
---|
85 | \fBTcl_Finalize\fR when \fBTcl\fR is being unloaded, to ensure that the |
---|
86 | code will work on all platforms. \fBTcl_Finalize\fR can be safely called |
---|
87 | more than once. |
---|
88 | .PP |
---|
89 | \fBTcl_ExitThread\fR is used to terminate the current thread and invoke |
---|
90 | per-thread exit handlers. This finalization is done by |
---|
91 | \fBTcl_FinalizeThread\fR, which you can call if you just want to clean |
---|
92 | up per-thread state and invoke the thread exit handlers. |
---|
93 | \fBTcl_Finalize\fR calls \fBTcl_FinalizeThread\fR for the current |
---|
94 | thread automatically. |
---|
95 | .PP |
---|
96 | \fBTcl_CreateExitHandler\fR arranges for \fIproc\fR to be invoked |
---|
97 | by \fBTcl_Finalize\fR and \fBTcl_Exit\fR. |
---|
98 | \fBTcl_CreateThreadExitHandler\fR arranges for \fIproc\fR to be invoked |
---|
99 | by \fBTcl_FinalizeThread\fR and \fBTcl_ExitThread\fR. |
---|
100 | This provides a hook for cleanup operations such as flushing buffers |
---|
101 | and freeing global memory. |
---|
102 | \fIProc\fR should match the type \fBTcl_ExitProc\fR: |
---|
103 | .CS |
---|
104 | typedef void Tcl_ExitProc(ClientData \fIclientData\fR); |
---|
105 | .CE |
---|
106 | The \fIclientData\fR parameter to \fIproc\fR is a |
---|
107 | copy of the \fIclientData\fR argument given to |
---|
108 | \fBTcl_CreateExitHandler\fR or \fBTcl_CreateThreadExitHandler\fR when |
---|
109 | the callback |
---|
110 | was created. Typically, \fIclientData\fR points to a data |
---|
111 | structure containing application-specific information about |
---|
112 | what to do in \fIproc\fR. |
---|
113 | .PP |
---|
114 | \fBTcl_DeleteExitHandler\fR and \fBTcl_DeleteThreadExitHandler\fR may be |
---|
115 | called to delete a |
---|
116 | previously-created exit handler. It removes the handler |
---|
117 | indicated by \fIproc\fR and \fIclientData\fR so that no call |
---|
118 | to \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, |
---|
123 | in reverse order from the order in which they were registered. |
---|
124 | This matches the natural order in which extensions are loaded and unloaded; |
---|
125 | if extension \fBA\fR loads extension \fBB\fR, it usually |
---|
126 | unloads \fBB\fR before it itself is unloaded. |
---|
127 | If 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 |
---|
129 | before the exit handlers for \fBA\fR. |
---|
130 | .PP |
---|
131 | \fBTcl_Finalize\fR and \fBTcl_Exit\fR call \fBTcl_FinalizeThread\fR |
---|
132 | and the thread exit handlers \fIafter\fR |
---|
133 | the process-wide exit handlers. This is because thread finalization shuts |
---|
134 | down the I/O channel system, so any attempt at I/O by the global exit |
---|
135 | handlers will vanish into the bitbucket. |
---|
136 | .PP |
---|
137 | .VS 8.5 |
---|
138 | \fBTcl_SetExitProc\fR installs an application exit handler, returning |
---|
139 | the previously-installed application exit handler or NULL if no |
---|
140 | application handler was installed. If an application exit handler is |
---|
141 | installed, that exit handler takes over complete responsibility for |
---|
142 | finalization of Tcl's subsystems via \fBTcl_Finalize\fR at an |
---|
143 | appropriate time. The argument passed to \fIproc\fR when it is |
---|
144 | invoked will be the exit status code (as passed to \fBTcl_Exit\fR) |
---|
145 | cast to a ClientData value. |
---|
146 | .VE 8.5 |
---|
147 | |
---|
148 | .SH KEYWORDS |
---|
149 | callback, cleanup, dynamic loading, end application, exit, unloading, thread |
---|