Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 7541238afe87c06a743e5978636cd3076b2b0de9f3f0df6cd0fcfde975045cc6
Ticket: 39680865953cce4fa7187d3613ff7707302d31a6
Basic nonblocking write-only refchan hangs
User & Date: apnadkarni on 2024-08-14 10:50:26
Changes

  1. icomment:
    Nathan, a working version of your channel implementation is below but first...
    
    *Nathan wrote: This fix is not the same as those that were previously argued, and the example that demonstrates the issue is also not the same. The previous arguments were about 1) whether an asynchronous channel should immediately signal writable when a channel is opened, and 2) whether postevent is asynchronous.*
    
    Not so. While 2) was a matter of requiring a TIP for incompatible changes to a public API where it could be discussed, 1) was only a symptom of a larger issue - continuous generation of "write" events without knowledge of actual channel state, something which completely defeats the purpose of event-based I/O turning it into a disguised polling model. The commit under discussion raises the same fears pending a thorough review, leave aside the question of whether those changes are even needed.
    
    *Nathan wrote: The core team should take care not to become a bottleneck to needed contributions.*
    
    While there will be some delay, I am afraid the time wasted this year chasing down and reverting or fixing commits that made it in without review is an order of magnitude higher.
    
    Getting to your sample script, below is a working version of a functionally similar refchan. The implementation is based on Aku's original paper. Note the refchan *implementation* may differ but I believe the *functionality* and *user* test code is the same as your refchan. Feel free to check that but my guess is that your refchan implementation has a bug or is incomplete as is the case in the two tickets you insist on reopening.
    
    ```
    namespace eval rc {
        namespace ensemble create
        namespace export *
        # Change to taste depending on how much CPU you want to hog
        variable delay 0
    
        proc finalize {chan args} {
            namespace upvar c_$chan timer timer buffer buffer
            catch {after cancel $timer}
            puts "Finalize: Have [string length $buffer] bytes."
            namespace delete c_$chan
        }
    
        proc initialize {chan args} {
            namespace eval c_$chan {}
            namespace upvar c_$chan watching watching timer timer buffer buffer
            set watching {}
            set buffer {}
            return {finalize initialize watch write}
        }
    
        proc watch {chan spec} {
            namespace upvar c_$chan watching watching
            set watching $spec
            update $chan
        }
    
        proc write {chan data} {
            namespace upvar c_$chan buffer buffer
            append buffer $data
            return [string length $data]
        }
    
        proc update {chan} {
            namespace upvar c_$chan watching watching timer timer
            variable delay
            catch {after cancel $timer}
            if {"write" in $watching} {
                set timer [after idle after $delay \
                               [namespace code [list post $chan]]]
            }
        }
    
        proc post {chan} {
            variable delay
            namespace upvar c_$chan watching watching timer timer
            if {"write" in $watching} {
                set timer [after idle after $delay \
                               [namespace code [list post $chan]]]
                chan postevent $chan write
            }
        }
    }
    
    set chan [chan create write [namespace which rc]]
    chan configure $chan -blocking 0
    coroutine c1 apply [list chan {
        after 0 [list [info coroutine]]
        yield
        chan event $chan writable [list [info coroutine]]
        while {[incr i] < 1000000}  {
            yield
            puts [list writing to $chan $i]
            puts $chan $i
        }
        set [namespace current]::done 1
    } [namespace current]] $chan
    vwait [namespace current]::done
    close $chan
    ```
    
    For explanation of above, please see Aku's paper.
    
  2. login: "apnadkarni"
  3. mimetype: "text/x-markdown"