Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 5cf3f5cc3965e0a369cfbabeb2f70825d10a6c2c0f36fc75950a1535013a9d0c
Ticket: 815e2468064b4324bc4b303b9bafd3ef92803c32
tcl crash on channel thread transfer and fileevent writable in place
User & Date: oehhar on 2018-06-08 07:34:54
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    <h1>Summary</h1>
    
    Transfering a channel to another thread by "thread::transfer" with a "fileevent writable" on the channel crashes tclsh after around 20 tries on Linux and Windows.
    The crash goes away, if the file event is cleared before the transfer.
    
    <h1>Crash</h1>
    
    Test script:
    
    <verbatim>
    package require Thread
    
    set handleproc {
        proc handle {chan} {
            global name other
            if {$name eq "master"} {
                puts $name
            } else {
                thread::send $other "puts slave"
            }
            thread::transfer $other $chan
            thread::send $other [list fileevent $chan writable [list handle $chan]]
        }
    }
    
    eval $handleproc
    set name master
    set other [thread::create]
    
    thread::send $other [list set name slave]
    thread::send $other [list set other [thread::id]]
    thread::send $other $handleproc
    
    set nulldev [dict get {unix /dev/null windows NUL}  $tcl_platform(platform)]
    set chan [open $nulldev RDWR]
    handle $chan
    
    vwait forever 
    </verbatim>
    
    <h1>Demonstration that it works without fileevent active</h1>
    
    The following script switches the event of before the transfer.
    It does not crash:
    
    <verbatim>
    package require Thread
    
    set handleproc {
        proc handle {chan} {
            global name other
            if {$name eq "master"} {
                puts $name
            } else {
                thread::send $other "puts slave"
            }
            thread::transfer $other $chan
            thread::send $other [subst {
                fileevent $chan writable {
                    fileevent $chan writable {}
                    after 0 handle $chan
                }
            }]
        }
    }
    
    eval $handleproc
    set name master
    set other [thread::create]
    
    thread::send $other [list set name slave]
    thread::send $other [list set other [thread::id]]
    thread::send $other $handleproc
    
    set nulldev [dict get {unix /dev/null windows NUL}  $tcl_platform(platform)]
    set chan [open $nulldev RDWR]
    handle $chan
    
    vwait forever 
    </verbatim>
    
    <h1>References</h1>
    
       *   Discussion thread on the core list titled: "TCL (Windows) socket driver and sending fd to another Thread" started 2018-06-07
       *   Bug report and test script by Reinhard Max
       *   cause analysis by Christian Werner
    
  5. foundin changed to: "8.6.8"
  6. is_private changed to: "0"
  7. login: "oehhar"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "oehhar"
  14. subsystem changed to: "49. Threading"
  15. title changed to:
    tcl crash on channel thread transfer and fileevent writable in place
    
  16. type changed to: "Bug"