Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2d3c9b8117891766607e9a75e8e3c9483ae1afce4a5ec2da4b1d3866a065c3ee
Ticket: de232b49f26da1c18e07513d4c7caa203cd27910
write-only nonblocking refchan and Tcl internal buffers
User & Date: pooryorick on 2019-04-26 20:53:55
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    Given the following write-only refchan, the coroutine attempting to use such a
    channel yields once and writes to the channel once.  After the coroutine yields
    a second time, the channel never becomes writable again and the coroutine is
    never entered again:
    
    
    <code><verbatim>
    namespace eval refchan {
        namespace ensemble create
        namespace export *
    
    
        proc finalize {chan args} {
            namespace delete c_$chan
        }
    
    
        proc initialize {chan args} {
            namespace eval c_$chan {}
            namespace upvar c_$chan watching watching
            set watching {}
            list finalize initialize seek watch write
        }
    
    
        proc watch {chan args} {
            namespace upvar c_$chan watching watching
            foreach arg $args {
                switch $arg {
                    write {
                        if {$arg ni $watching} {
                            lappend watching $arg
                        }
                        chan postevent $chan $arg
                    }
                }
            }
        }
    
    
        proc write {chan args} {
            chan postevent $chan write
            return 1
        }
    }
    
    
    after 0  [list coroutine c1 apply [list {} {
        set chan [chan create write refchan]
        chan configure $chan -blocking 0
        chan event $chan writable [list [info coroutine]]
        for {set i 0} {$i < 10} {incr i} {
            yield
            puts $chan hello
        }
        set ::done 1
    }]]
    vwait done
    </verbatim></code>
    
    
    The problem is that <code>tclIO.c/Write</code> adds the value from the first
    write into an internal buffer but takes no actions that result in another call
    to <code>Tcl_NotifyChannel</code>.  In particular, the "write" command of the
    reference channel is never called because the result of
    <code>IsBufferFull</code> is "false".
    
  5. is_private changed to: "0"
  6. login: "pooryorick"
  7. priority changed to: "5 Medium"
  8. resolution changed to: "None"
  9. severity changed to: "Minor"
  10. status changed to: "Open"
  11. submitter changed to: "pooryorick"
  12. subsystem changed to: "- New Builtin Commands"
  13. title changed to:
    write-only nonblocking refchan and Tcl internal buffers
    
  14. type changed to: "Bug"