Index: doc/html/thread.html
==================================================================
--- doc/html/thread.html
+++ doc/html/thread.html
@@ -124,11 +124,11 @@
thread::release ?-wait? ?id?
thread::id
thread::errorproc ?procname?
thread::cancel ?-unwind? id ?result?
thread::unwind
-thread::exit
+thread::exit ?status?
thread::names
thread::exists id
thread::send ?-async? ?-head? id script ?varname?
thread::broadcast script
thread::wait
@@ -300,22 +300,23 @@
the script passed to newly created thread will continue from the
thread::wait command. If thread::wait was the last command
in the script, the thread will exit. The command returns empty result
but may trigger Tcl error with the message "target thread died" in some
situations.
-thread::exit
+thread::exit ?status?
Use of this command is deprecated in favour of more advanced thread
reservation system implemented with thread::preserve and
thread::release commands. Support for thread::exit
command will dissapear in some future major release of the extension.
-This command forces a thread stuck in the thread::wait
-command to unconditionaly exit. The execution of thread::exit
-command is guaranteed to leave the program memory in the unconsistent
-state, produce memory leaks and otherwise affect other subsytem(s)
-of the Tcl application in an unpredictable manner. The command
-returns empty result but may trigger Tcl error with the message
-"target thread died" in some situations.
+This command forces a thread stuck in the thread::wait command to
+unconditionaly exit. The thread's exit status defaults to 666 and can be
+specified using the optional status argument. The execution of
+thread::exit command is guaranteed to leave the program memory in the
+unconsistent state, produce memory leaks and otherwise affect other subsytem(s)
+of the Tcl application in an unpredictable manner. The command returns empty
+result but may trigger Tcl error with the message "target thread died" in some
+situations.
thread::names
This command returns a list of thread IDs. These are only for
threads that have been created via thread::create command.
If your application creates other threads at the C level, they
are not reported by this command.
Index: doc/man/thread.n
==================================================================
--- doc/man/thread.n
+++ doc/man/thread.n
@@ -289,11 +289,11 @@
.sp
\fBthread::cancel\fR ?-unwind? \fIid\fR ?result?
.sp
\fBthread::unwind\fR
.sp
-\fBthread::exit\fR
+\fBthread::exit\fR ?status?
.sp
\fBthread::names\fR
.sp
\fBthread::exists\fR \fIid\fR
.sp
@@ -512,23 +512,24 @@
\fBthread::wait\fR command\&. If \fBthread::wait\fR was the last command
in the script, the thread will exit\&. The command returns empty result
but may trigger Tcl error with the message "target thread died" in some
situations\&.
.TP
-\fBthread::exit\fR
+\fBthread::exit\fR ?status?
Use of this command is deprecated in favour of more advanced thread
reservation system implemented with \fBthread::preserve\fR and
\fBthread::release\fR commands\&. Support for \fBthread::exit\fR
command will dissapear in some future major release of the extension\&.
.sp
-This command forces a thread stuck in the \fBthread::wait\fR
-command to unconditionaly exit\&. The execution of \fBthread::exit\fR
-command is guaranteed to leave the program memory in the unconsistent
-state, produce memory leaks and otherwise affect other subsytem(s)
-of the Tcl application in an unpredictable manner\&. The command
-returns empty result but may trigger Tcl error with the message
-"target thread died" in some situations\&.
+This command forces a thread stuck in the \fBthread::wait\fR command to
+unconditionaly exit\&. The thread's exit status defaults to 666 and can be
+specified using the optional \fIstatus\fR argument\&. The execution of
+\fBthread::exit\fR command is guaranteed to leave the program memory in the
+unconsistent state, produce memory leaks and otherwise affect other subsytem(s)
+of the Tcl application in an unpredictable manner\&. The command returns empty
+result but may trigger Tcl error with the message "target thread died" in some
+situations\&.
.TP
\fBthread::names\fR
This command returns a list of thread IDs\&. These are only for
threads that have been created via \fBthread::create\fR command\&.
If your application creates other threads at the C level, they
Index: doc/thread.man
==================================================================
--- doc/thread.man
+++ doc/thread.man
@@ -197,24 +197,25 @@
in the script, the thread will exit. The command returns empty result
but may trigger Tcl error with the message "target thread died" in some
situations.
-[call [cmd thread::exit]]
+[call [cmd thread::exit] [opt status]]
Use of this command is deprecated in favour of more advanced thread
reservation system implemented with [cmd thread::preserve] and
[cmd thread::release] commands. Support for [cmd thread::exit]
command will dissapear in some future major release of the extension.
[para]
-This command forces a thread stuck in the [cmd thread::wait]
-command to unconditionaly exit. The execution of [cmd thread::exit]
-command is guaranteed to leave the program memory in the unconsistent
-state, produce memory leaks and otherwise affect other subsytem(s)
-of the Tcl application in an unpredictable manner. The command
-returns empty result but may trigger Tcl error with the message
-"target thread died" in some situations.
+This command forces a thread stuck in the [cmd thread::wait] command to
+unconditionaly exit. The thread's exit status defaults to 666 and can be
+specified using the optional [arg status] argument. The execution of
+[cmd thread::exit] command is guaranteed to leave the program memory in the
+unconsistent state, produce memory leaks and otherwise affect other subsytem(s)
+of the Tcl application in an unpredictable manner. The command returns empty
+result but may trigger Tcl error with the message "target thread died" in some
+situations.
[call [cmd thread::names]]
This command returns a list of thread IDs. These are only for
threads that have been created via [cmd thread::create] command.
Index: generic/threadCmd.c
==================================================================
--- generic/threadCmd.c
+++ generic/threadCmd.c
@@ -783,15 +783,28 @@
ClientData dummy; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int objc; /* Number of arguments. */
Tcl_Obj *const objv[]; /* Argument objects. */
{
+ int status = 666;
Init(interp);
+
+ if (objc > 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "?status?");
+ return TCL_ERROR;
+ }
+
+ if (objc == 2) {
+ if (Tcl_GetIntFromObj(interp, objv[1], &status) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ }
+
ListRemove(NULL);
- Tcl_ExitThread(666);
+ Tcl_ExitThread(status);
return TCL_OK; /* NOT REACHED */
}
/*
Index: tests/thread.test
==================================================================
--- tests/thread.test
+++ tests/thread.test
@@ -144,10 +144,30 @@
set tid [thread::create -joinable {thread::exit}]
set c [thread::join $tid]
ThreadReap
set c
} {666}
+
+test thread-7.1 {thread::exit - # args} {
+ set tid [thread::create]
+ catch {thread::send $tid {thread::exit 1 0}} msg
+ set msg
+} {wrong # args: should be "thread::exit ?status?"}
+
+test thread-7.2 {thread::exit - args} {
+ set tid [thread::create]
+ catch {thread::send $tid {thread::exit foo}} msg
+ set msg
+} {expected integer but got "foo"}
+
+test thread-7.3 {thread::exit - status} {
+ ThreadReap
+ set tid [thread::create -joinable {thread::exit 0}]
+ set c [thread::join $tid]
+ ThreadReap
+ set c
+} {0}
test thread-8.0 {thread::exists - true} {
ThreadReap
set c [thread::exists [thread::create]]
ThreadReap