OriginalBugID: 4616 Bug
Version: 8.3
SubmitDate: '2000-03-27'
LastModified: '2000-04-25'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 4846 4913
OS: Linux-SuSE
FixedDate: '2000-04-25'
FixedInVersion: 8.3.1
ClosedDate: '2000-10-25'
Name:
Andreas Kupries
CVS:
Mar 25, 2000
Comments:
Addition of 'all.tcl' and most changes to the test file were done so
that the output of the testsuite is like the output for other
extensions, etc. (statistics at the end). When doing this an error was
found and fixed as well: The tcltest package uses the mainThread
variable to hold the id of the main thread, to avoid killing it after
reaping threads generated by a test. This variable was not correctly
initialized, shutting down the test runs in test thread-1.4 by reaping
the main thread too. This was fixed by modifying 'all.tcl' as follows.
Please note that the patch below is given only to show the fix,
application is **not** required. The change is already part of the
submitted full patch. 'all.tcl' was originally copied unchanged from
'tcl8.3.0/tests/all.tcl'.
--- ../arch/current/tcl/tests/all.tclSat Mar 11 17:11:30 2000
+++ thread/tests/all.tclFri Mar 24 21:32:36 2000
@@ -39,6 +39,17 @@
set timeCmd {clock format [clock seconds]}
puts stdout "Tests began at [eval $timeCmd]"
+
+# these tests need to know which is the main thread
+# (and the detection in tcltest is flawed since it
+# still expects only testhread, causing the system
+# to exit after test 1.3)
+
+package require Thread 2.0
+set ::tcltest::mainThread [thread names]
+
+puts stdout "Mainthread is $::tcltest::mainThread"
+
# source each of the specified tests
foreach file [lsort [::tcltest::getMatchingFiles]] {
set tail [file tail $file]
ReproducibleScript:
This bug report is actually about the "thread" extension in the CVS. The patch below adds a manpage, fixes a minor nit in the html documentation and makes the testsuite work as expected. The manpage is necessary to satisfy the "install-doc" target of the Makefile.
Patch:
diff -ruN thread.orig/doc/thread.html thread/doc/thread.html
--- thread.orig/doc/thread.htmlFri Mar 24 21:30:19 2000
+++ thread/doc/thread.htmlFri Mar 24 21:31:37 2000
@@ -36,7 +36,7 @@
The <i>proc</i> is called like this:
<ul>
<pre>
-myerroproc thread_id errorInfo
+myerrorproc thread_id errorInfo
</pre>
</ul>
<p>
diff -ruN thread.orig/doc/thread.n thread/doc/thread.n
--- thread.orig/doc/thread.nThu Jan 1 01:00:00 1970
+++ thread/doc/thread.nFri Mar 24 21:31:37 2000
@@ -0,0 +1,86 @@
+'\"
+'\" Copyright (c) 2000 Andreas Kupries
+'\"
+'\" See the file "license.terms" for information on usage and redistribution
+'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+'\"
+'\" SCCS: @(#) thread.n
+'\"
+.so man.macros
+.TH "thread" n 2.0 Tcl "Tcl Threading"
+.BS
+'\" Note: do not modify the .SH NAME line immediately below!
+.SH NAME
+thread \- Script level threading
+.SH "SYNOPSIS"
+\fB thread create ?\fIscript\fR?
+\fB thread \fIid\fR
+\fB thread errorproc \fIprocname\fR
+\fB thread exit
+\fB thread names
+\fB thread send id ?\fI-async\fR? \fIscript\fR
+\fB thread wait
+.BE
+.SH "DESCRIPTION"
+.PP
+The \fBthread\fR command creates threads that contain Tcl interpreters, and
+it lets you send scripts to those threads.
+
+\fBthread create\fR creates a thread that contains a Tcl
+interpreter. The Tcl interpreter either evaluates the \fIscript\fR, if
+specified, or it waits in the event loop for scripts that arrive via
+the \fBthread send\fR command. The result of \fBthread create\fR
+is the ID of the thread. The result, if any, of \fIscript\fR is
+ignored.
+
+\fBthread id\fR returns the ID of the current thread.
+
+\fBthread errorproc\fR sets a handler for errors that occur in other
+threads. By default, an uncaught error in a thread terminates that
+thread and causes an error message to be sent to the standard error
+channel. You can change the default reporting scheme by registering a
+procedure that is called to report the error. The \fIproc\fR is called
+in the interpreter that invoked the \fBthread errorproc\fR
+command. The original thread that has the uncaught error is terminated
+in any case. The \fIproc\fR is called like this:
+
+ myerrorproc thread_id errorInfo
+
+\fBthread exit\fR terminates the current thread. There is no way to force
+another thread to exit - you can only ask it to terminate by sending
+it a command.
+
+\fBthread names\fR returns a list of thread IDs. These are only for
+threads that have been created via \fBthread create\fR. If your
+application creates other threads at the C level, they are not
+reported by \fBthread names\fR.
+
+\fBthread send\fR passes a \fIscript\fR to another thread and,
+optionally, waits for the result. If the \fB-async\fR flag is
+specified then the caller does not wait for the result. The target
+thread must enter its event loop in order to receive script
+messages. This is done by default for threads created without a
+startup script. Threads can enter the event loop explicitly by calling
+\fBthread wait\fR or \fBvwait\fR.
+
+\fBthread wait\fR enters the event loop so a thread can receive
+messages from \fBthread send\fR. This is equivalent to \fBvwait\fR
+\fIunusedvariable\fR.
+.SH "DISCUSSION"
+The fundamental threading model in Tcl is that there can be one or
+more Tcl interpreters per thread, but each Tcl interpreter should only
+be used by a single thread. A "shared memory" abstraction is awkward
+to provide in Tcl because Tcl makes assumptions about variable and
+data ownership. Therefore this extension supports a simple form of
+threading where the main thread can manage several background, or
+"worker" threads. For example, an event-driven server can pass
+requests to worker threads, and then await responses from worker
+threads or new client requests. Everything goes through the common Tcl
+event loop, so message passing between threads works naturally with
+event-driven I/O, \fBvwait\fR on variables, and so forth.
+.SH "SEE ALSO"
+Guide to the Tcl threading model
+.SH "CREDITS"
+.PP
+.SH "KEYWORDS"
+threads, events, message passing
diff -ruN thread.orig/tests/all.tcl thread/tests/all.tcl
--- thread.orig/tests/all.tclThu Jan 1 01:00:00 1970
+++ thread/tests/all.tclFri Mar 24 21:32:36 2000
@@ -0,0 +1,66 @@
+# all.tcl --
+#
+# This file contains a top-level script to run all of the Tcl
+# tests. Execute it by invoking "source all.test" when running tcltest
+# in this directory.
+#
+# Copyright (c) 1998-1999 by Scriptics Corporation.
+# All rights reserved.
+#
+# RCS: @(#) $Id: all.tcl,v 1.9 2000/01/27 23:44:09 jenn Exp $
+
+if {[lsearch [namespace children] ::tcltest] == -1} {
+ package require tcltest
+ namespace import ::tcltest::*
+}
+
+set ::tcltest::testSingleFile false
+set ::tcltest::testsDirectory [file dir [info script]]
+
+# We need to ensure that the testsDirectory is absolute
+::tcltest::normalizePath ::tcltest::testsDirectory
+
+puts stdout "Tcl $tcl_patchLevel tests running in interp: [info nameofexecutable]"
+puts stdout "Tests running in working dir: $::tcltest::testsDirectory"
+if {[llength $::tcltest::skip] > 0} {
+ puts stdout "Skipping tests that match: $::tcltest::skip"
+}
+if {[llength $::tcltest::match] > 0} {
+ puts stdout "Only running tests that match: $::tcltest::match"
+}
+
+if {[llength $::tcltest::skipFiles] > 0} {
+ puts stdout "Skipping test files that match: $::tcltest::skipFiles"
+}
+if {[llength $::tcltest::matchFiles] > 0} {
+ puts stdout "Only sourcing test files that match: $::tcltest::matchFiles"
+}
+
+set timeCmd {clock format [clock seconds]}
+puts stdout "Tests began at [eval $timeCmd]"
+
+
+# these tests need to know which is the main thread
+# (and the detection in tcltest is flawed since it
+# still expects only testhread, causing the system
+# to exit after test 1.3)
+
+package require Thread 2.0
+set ::tcltest::mainThread [thread names]
+
+puts stdout "Mainthread is $::tcltest::mainThread"
+
+# source each of the specified tests
+foreach file [lsort [::tcltest::getMatchingFiles]] {
+ set tail [file tail $file]
+ puts stdout $tail
+ if {[catch {source $file} msg]} {
+puts stdout $msg
+ }
+}
+
+# cleanup
+puts stdout "\nTests ended at [eval $timeCmd]"
+::tcltest::cleanupTests 1
+return
+
diff -ruN thread.orig/tests/thread.test thread/tests/thread.test
--- thread.orig/tests/thread.testFri Mar 24 21:30:19 2000
+++ thread/tests/thread.testFri Mar 24 21:32:36 2000
@@ -12,8 +12,10 @@
#
# RCS: @(#) $Id: thread.test,v 1.1.1.1 2000/01/19 22:57:24 welch Exp $
-package require tcltest
-namespace import ::tcltest::*
+if {[lsearch [namespace children] ::tcltest] == -1} {
+ package require tcltest
+ namespace import ::tcltest::*
+}
package require Thread 2.0
@@ -37,7 +39,7 @@
}
}
## Enter a bit of sleep to give the threads enough breathing
-## room to kill themselves off, otherwise the end up with a
+## room to kill themselves off, otherwise we end up with a
## massive queue of repeated events
after 1
}
PatchFiles:
thread.html
thread.n (new)
thread.test
all.tcl (new)
Adopted for thread extension to coincide with 8.3.1
-- 04/25/2000 hobbs
|