diff options
Diffstat (limited to 'tests/thread.test')
-rw-r--r-- | tests/thread.test | 107 |
1 files changed, 43 insertions, 64 deletions
diff --git a/tests/thread.test b/tests/thread.test index febc7a8..f32ef61 100644 --- a/tests/thread.test +++ b/tests/thread.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. -if {"::tcltest" ni [namespace children]} { +if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.2 namespace import -force ::tcltest::* } @@ -42,11 +42,11 @@ set threadSuperKillScript { proc getThreadErrorFromInfo { info } { set list [split $info \n] set idx [lsearch -glob $list "*eval*unwound*"] - if {$idx != -1} { + if {$idx != -1} then { return [lindex $list $idx] } set idx [lsearch -glob $list "*eval*canceled*"] - if {$idx != -1} { + if {$idx != -1} then { return [lindex $list $idx] } return ""; # some other error we do not care about. @@ -55,7 +55,7 @@ proc getThreadErrorFromInfo { info } { proc findThreadError { info } { foreach error [lreverse $info] { set error [getThreadErrorFromInfo $error] - if {[string length $error] > 0} { + if {[string length $error] > 0} then { return $error } } @@ -64,7 +64,7 @@ proc findThreadError { info } { proc ThreadError {id info} { global threadSawError - if {[string length [getThreadErrorFromInfo $info]] > 0} { + if {[string length [getThreadErrorFromInfo $info]] > 0} then { global threadId threadError set threadId $id lappend threadError($id) $info @@ -84,28 +84,6 @@ if {[testConstraint testthread]} { } testthread errorproc ThreadError - - set mainThread [testthread id] - - proc ThreadNullError {id info} { - # ignore - } - - proc threadReap {} { - testthread errorproc ThreadNullError - while {[llength [testthread names]] > 1} { - foreach tid [testthread names] { - if {$tid != [testthread id]} { - catch { - testthread send -async $tid {testthread exit} - } - } - } - after 1 - } - testthread errorproc ThreadError - return [llength [testthread names]] - } } # Some tests require manual draining of the event queue @@ -159,7 +137,7 @@ test thread-1.15 {Tcl_ThreadObjCmd: wait} {thread} { # ThreadErrorProc, except for printing to standard error test thread-2.1 {ListUpdateInner and ListRemove} {thread} { - unset -nocomplain tid + catch {unset tid} foreach t {0 1 2} { upvar #0 t$t tid set tid [thread::create -preserved] @@ -172,7 +150,7 @@ test thread-2.1 {ListUpdateInner and ListRemove} {thread} { } 1 test thread-3.1 {TclThreadList} {thread} { - unset -nocomplain tid + catch {unset tid} set len [llength [thread::names]] set l1 {} foreach t {0 1 2} { @@ -187,7 +165,7 @@ test thread-3.1 {TclThreadList} {thread} { } {1 0} test thread-4.1 {TclThreadSend to self} {thread} { - unset -nocomplain x + catch {unset x} thread::send [thread::id] { set x 4 } @@ -233,6 +211,7 @@ test thread-4.5 {TclThreadSend preserve errorCode} {thread} { list $x $msg $savedErrorCode } {1 ERR CODE} + test thread-5.0 {Joining threads} {thread} { set serverthread [thread::create -joinable -preserved] thread::send -async $serverthread {after 1000 ; thread::release} @@ -274,7 +253,7 @@ test thread-7.4 {cancel: pure bytecode loop} -constraints {thread drainEventQueu set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -305,7 +284,7 @@ test thread-7.5 {cancel: pure inside-command loop} -constraints {thread drainEve set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -337,7 +316,7 @@ test thread-7.6 {cancel: pure bytecode loop -unwind} -constraints {thread drainE set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -368,7 +347,7 @@ test thread-7.7 {cancel: pure inside-command loop -unwind} -constraints {thread set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -400,7 +379,7 @@ test thread-7.8 {cancel: pure bytecode loop custom result} -constraints {thread set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -434,7 +413,7 @@ test thread-7.9 {cancel: pure inside-command loop custom result} -constraints { set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -469,7 +448,7 @@ test thread-7.10 {cancel: pure bytecode loop custom result -unwind} -constraints set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -503,7 +482,7 @@ test thread-7.11 {cancel: pure inside-command loop custom result -unwind} -const set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { proc foobar {} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -534,7 +513,7 @@ test thread-7.12 {cancel: after} -constraints {thread drainEventQueue} -setup { } -body { set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -560,7 +539,7 @@ test thread-7.13 {cancel: after -unwind} -constraints {thread drainEventQueue} - } -body { set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -586,7 +565,7 @@ test thread-7.14 {cancel: vwait} -constraints {thread drainEventQueue} -setup { } -body { set serverthread [thread::create -joinable \ [string map [list %ID [thread::id]] { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -612,7 +591,7 @@ test thread-7.15 {cancel: vwait -unwind} -constraints {thread drainEventQueue} - } -body { set serverthread [thread::create -joinable \ [string map [list %ID% [thread::id]] { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -641,7 +620,7 @@ test thread-7.16 {cancel: expr} -constraints {thread drainEventQueue} -setup { set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). @@ -672,7 +651,7 @@ test thread-7.17 {cancel: expr -unwind} -constraints {thread drainEventQueue} -s set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -701,7 +680,7 @@ test thread-7.18 {cancel: expr bignum} {thread drainEventQueue knownBug} { set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -733,7 +712,7 @@ test thread-7.19 {cancel: expr bignum -unwind} {thread drainEventQueue knownBug} set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -766,7 +745,7 @@ test thread-7.20 {cancel: subst} -constraints {thread drainEventQueue} -setup { set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -796,7 +775,7 @@ test thread-7.21 {cancel: subst -unwind} -constraints {thread drainEventQueue} - set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -826,7 +805,7 @@ test thread-7.22 {cancel: slave interp} -constraints {thread drainEventQueue} -s set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -856,7 +835,7 @@ test thread-7.23 {cancel: slave interp -unwind} -constraints {thread drainEventQ set i [interp create] $i eval "package require -exact Thread [package present Thread]" $i eval { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -884,7 +863,7 @@ test thread-7.24 {cancel: nested catch inside pure bytecode loop} {thread drainE [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -926,7 +905,7 @@ test thread-7.25 {cancel: nested catch inside pure inside-command loop} {thread set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -966,7 +945,7 @@ test thread-7.26 {cancel: send async cancel bad interp path} {thread drainEventQ [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -995,7 +974,7 @@ test thread-7.27 {cancel: send async cancel -- switch} -constraints {thread drai $i eval { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1026,7 +1005,7 @@ test thread-7.28 {cancel: send async cancel nested catch inside pure bytecode lo [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1068,7 +1047,7 @@ test thread-7.29 {cancel: send async cancel nested catch pure inside-command loo set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1108,7 +1087,7 @@ test thread-7.30 {cancel: send async thread cancel nested catch inside pure byte [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1150,7 +1129,7 @@ test thread-7.31 {cancel: send async thread cancel nested catch pure inside-comm set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1191,7 +1170,7 @@ test thread-7.32 {cancel: nested catch inside pure bytecode loop -unwind} -const [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1232,7 +1211,7 @@ test thread-7.33 {cancel: nested catch inside pure inside-command loop -unwind} set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1271,7 +1250,7 @@ test thread-7.34 {cancel: send async cancel nested catch inside pure bytecode lo [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1314,7 +1293,7 @@ test thread-7.35 {cancel: send async cancel nested catch inside pure inside-comm set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1355,7 +1334,7 @@ test thread-7.36 {cancel: send async thread cancel nested catch inside pure byte [string map [list %ID% [thread::id]] { proc foobar {} { while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] @@ -1398,7 +1377,7 @@ test thread-7.37 {cancel: send async thread cancel nested catch inside pure insi set catch catch set while while $while {1} { - if {![info exists foo]} { + if {![info exists foo]} then { # signal the primary thread that we are ready # to be canceled now (we are running). thread::send %ID% [list set ::threadIdStarted [thread::id]] |