Overview
| Artifact ID: | 1664d3369740e287dd22192f3036532dfb6fa42316981c05e4535fc975486e93 |
|---|---|
| Ticket: | b78d94c049af5090a9ef1c4aaa8059aa45b98b59
Thread pool panics if stdin closed and IO performed in initcmd |
| User & Date: | sebres on 2025-02-24 23:20:20 |
Changes
- closedate changed to: "2460731.47246301"
- closer changed to: "sebres"
- icomment:
Well, it looks like this is indeed an issue of tcl (not the thread-module). Here is the experimental commit that solves the issue - [93d9a20635]. Although I'm not quite convinced with this solution. In general the usage of standard channels across threads is not well thought out in tcl-IO: <ul> <li>the standard channels (by their names) are "shared" across the threads, however not the instances of them (which are quasi duplicates each thread);</li> <li>so every thread initializes its own instance, so that if a thread uses some of standard channel first time, it gets its own instance (for the same thing)</li> <li>the close of standard channel in one thread will do that not for the other thread, if both already touched it, but new thread may miss it</li> <li>the whole thing is additionally platform-specific (and may deviate e. g. by windows if it is closes in main thread, the new thread cannot obtain a new standard handle in new thread, on linux it'd be able to do that.</li> <li>to handle it properly, one has to know how many threads using some standard channel (e. g. N threads in use, but M thread ever touched some channel), inclusive possible timing issues on some race condition.</li> </ul> Basically the proper and consistent solution can be: <ol> <li>either real sharing of standard channels across the threads (and common global array of them), what would be not so simple since tcl doesn't know about "sharing" of channels at all;</li> <li>or fully independent standard channels across the threads (may be again platform-specific thing or at least backwards incompatible);</li> <li>and/or complete avoidance of implicit reassignment of standard channels by open after close (need then some command to do that explicitly if wanted).</li> </ol> In any case it needs a clear definition what shall happen multi-threaded by closing of standard channels (in "shared" and "unshared" state), because at the moment it is rather an UB, and "duplicate channel names" error is rather an after-effect.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"