Skip to content
Tcl Source Code History Of Ticket e8efa378a96bca5e
Login

History Of Ticket e8efa378a96bca5e

Artifacts Associated With Ticket e8efa378a96bca5e

  1. Ticket change [56c6207321] (rid 133526) by JKU on 2013-08-29 12:44:17:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      When I create/open a channel in an other Thread (created with <code>thread::create</code>) the names of the first 3 opened channels are <code>stdin</code>, <code>stdout</code> and <code>stderr</code>, as described on the [http://www.tcl.tk/man/tcl8.6/TclLib/StdChannels.htm|Tcl_StandardChannels manual page].
      
      <verbatim>
      % file channels
      stdout stderr stdin
      % package require Thread
      2.6.7
      % set tid [thread::create]
      % thread::send $tid {package require tcl::chan::string}
      1.0.1
      % thread::send $tid {::tcl::chan::string "Hello World\n"}
      stdin
      % thread::send $tid {open test.txt w}
      stdout
      % thread::send $tid {file channels}
      stdin stdout
      </verbatim>
      
      This will probably cause problems when transfering the channels.
      
    5. foundin initialized to: "8.6.0"
    6. is_private initialized to: "0"
    7. login: "JKU"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Severe"
    11. status initialized to: "Open"
    12. submitter initialized to: "JKU"
    13. subsystem initialized to: "25. Channel System"
    14. title initialized to: "Duplicate std* channels in different Threads"
    15. type initialized to: "Bug"
  2. Ticket change [9e671dd620] (rid 133527) by JKU on 2013-08-29 12:47:38:

    1. comment changed to:
      When I create/open a channel in an other Thread (created with <code>thread::create</code>) the names of the first 3 opened channels are <code>stdin</code>, <code>stdout</code> and <code>stderr</code>, as described on the [http://www.tcl.tk/man/tcl8.6/TclLib/StdChannels.htm|Tcl_StandardChannels manual page].
      
      <verbatim>
      % file channels
      stdout stderr stdin
      % package require Thread
      2.6.7
      % set tid [thread::create]
      tid000006C0
      % thread::send $tid {package require tcl::chan::string}
      1.0.1
      % thread::send $tid {::tcl::chan::string "Hello World\n"}
      stdin
      % thread::send $tid {open test.txt w}
      stdout
      % thread::send $tid {file channels}
      stdin stdout
      </verbatim>
      
      This will probably cause problems when transfering the channels.
      
      This behavior was not reproducable with tclsh, only wish seems to be affected.
      
    2. login: "JKU"
    3. mimetype: "text/plain"
  3. Ticket change [b347794474] (rid 133528) by JKU on 2013-08-29 12:56:03:

    1. icomment:
      The transfer of such channels will fail with the error <code>channel is shared</code>.
      
      With Tclsh, the new Thread has all 3 std* channels.
      
    2. login: "JKU"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "JKU"
  4. Ticket change [ef365875ea] (rid 133529) by JKU on 2013-08-29 13:35:53:

    1. icomment:
      Tclsh, not the intended behavior:
      
      <verbatim>
      % interp create
      interp0
      % package r Thread
      2.6.7
      % set tid [thread::create]
      tid000019C8
      % thread::send $tid {close stdout}
      puts hello
      error writing "stdout": bad file number
      </verbatim>
      
    2. login: "JKU"
    3. mimetype: "text/x-fossil-wiki"
  5. Ticket change [3d829265d5] (rid 133559) by dgp on 2013-08-30 15:07:19:

    1. assignee changed to: "aku"
    2. login: "dgp"
    3. mimetype: "text/plain"
  6. Ticket change [0006c77edc] (rid 258056) by serhiy.storchaka on 2026-10-14 18:14:04:

    1. icomment:
      The first part is the documented behavior. In wish on Windows a new thread has no standard channels, and as described in Tcl_StandardChannels(3), "the first three Tcl channels then opened by the application are designated as the Tcl standard channels"; a standard channel cannot be transferred. On Linux, and in tclsh on Windows (as you wrote), the new thread gets its own stdin, stdout and stderr.
      
      The second part is expected too: the standard channels of all threads refer to the same standard handles of the process, so closing stdout in one thread closes the process's standard output, just as closing stdout does in a single-threaded program.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Invalid"
    5. status changed to: "Closed"
  7. Ticket change [c119671225] (rid 258073) by JKU on 2026-10-14 19:40:19:

    1. icomment:
      "the standard channels of all threads refer to the same standard handles of the process"
      
      As shown in the reproducer, this is not true at all - new channels in other threads may refer to different channels, even if they have the same name.
      
      Closing those does NOT close the process standard input.
      
    2. login: "JKU"
    3. mimetype: "text/plain"
    4. resolution changed to: "None"
    5. status changed to: "Open"
  8. Ticket change [cd8a690d99] (rid 258082) by serhiy.storchaka on 2026-10-14 19:53:36:

    1. icomment:
      You are right, that sentence was too general. In wish on Windows the standard channel names in a new thread are just given to the first channels opened there (test.txt etc. in your example), so closing them closes only those channels. The sentence applies to tclsh (your second example): there stdout of every thread refers to the same file descriptor 1, so closing stdout in one thread breaks stdout of the main thread.
      
      That ordinary channels become standard channels in a thread without platform standard channels is still the behavior documented in Tcl_StandardChannels(3). Not doing that in threads other than the main thread would be a change of that behavior, which needs a decision.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [c65c24cddc] (rid 258083) by JKU on 2026-10-14 20:05:01:

    1. icomment:
      And that is my problem here:
      
      * New channels in other threads may get std* names.
      * Those channels can not be transferred to other threads.
      * Related, but maybe a different bug: closing std* channels closes the underlying fd/handle, but leaves the channel hanging.
      
      This results in:
      
      * Extra code may be needed to "occupy" the channel names if a channel should be created with the intention to transfer it later.
      * Complicated mental model around standard channels.
      
      I did hope that there would be a discussion about this, with may result in (your pick):
      
      * All std* refer to the same underlying fd/handle, regardless if executed on wish/tclsh.
      * Closing std* channels makes them disappear in all threads.
      * Creating new channels does not name them std* if an other thread already has a channel with that name.
      
      or
      
      * Channels created with a name like std* are shared across all threads.
      
      I think that there might be some improvement in the way Tcl handles replacing std* channels and threads.
      
      The current behavior is documented, but... I am not really happy with it as it stands.
      
    2. login: "JKU"
    3. mimetype: "text/x-markdown"
  10. Ticket change [e9207a7218] (rid 258084) by serhiy.storchaka on 2026-10-14 20:21:04:

    1. icomment:
      Thank you, I understand now. This would change documented behavior, so it should be discussed on tcl-core first.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"