Overview
| Artifact ID: | 17bbdd776b15ec91aa772e3f7125ac2d3b82b5ee |
|---|---|
| Ticket: | 894da183c8475264b8070b5b4dbbd6dd72f8dd69
In a thread, switch a non-blocking channel to blocking and close == hang |
| User & Date: | pooryorick on 2015-04-24 22:51:10 |
Changes
- comment changed to:
The following script causes Tcl to hang: <code><verbatim> #! /bin/env tclsh package require Thread lassign [chan pipe] pr pw # Comment this out and the interpreter no-longer hangs. chan configure $pw -blocking 0 set tid [thread::create] thread::transfer $tid $pw thread::send $tid [list variable pw $pw] thread::send $tid [list lappend notify_condition $pw] thread::send -async $tid { #after 5000 apply {{} { variable notify_condition variable pw for {set i 0} {$i < 10000} {incr i} { puts $pw [string repeat [info cmdcount] 15] } foreach chan $notify_condition { chan configure $chan -blocking 1 close $chan } }} thread::release } after 5000 set data [read $pr] close $pr puts {condition occured} </verbatim></code> Add a call to <code>[flush]</code> after enabling blocking, and the script no longer hangs: <code><verbatim> #! /bin/env tclsh package require Thread lassign [chan pipe] pr pw # Comment this out and the interpreter no-longer hangs. chan configure $pw -blocking 0 set tid [thread::create] thread::transfer $tid $pw thread::send $tid [list variable pw $pw] thread::send $tid [list lappend notify_condition $pw] thread::send -async $tid { #after 5000 apply {{} { variable notify_condition variable pw for {set i 0} {$i < 10000} {incr i} { puts $pw [string repeat [info cmdcount] 15] } foreach chan $notify_condition { chan configure $chan -blocking 1 flush $chan close $chan } }} thread::release } after 5000 set data [read $pr] close $pr puts {condition occured} </verbatim></code> - login: "pooryorick"
- mimetype: "text/x-fossil-wiki"