|
2018-03-05
| ||
| 17:50 | • Closed ticket [1873ea0ee4]: open channel "nul" within non-main thread ... artifact: 46b20943ca user: sebres | |
| 17:43 | merge core-8-5-branch (fixes [1873ea0ee4f01b26]: wrong initialization of std-channels ...) check-in: 6b38bf6d66 user: sebres tags: core-8-6-branch | |
| 17:37 | fixes [1873ea0ee4f01b26]: wrong initialization of std-channels, if no std-handles available at all (... check-in: 041bc74867 user: sebres tags: core-8-5-branch | |
| 16:18 | • Ticket [1873ea0ee4] open channel "nul" within non-main thread on windo... artifact: ba7942e639 user: sebres | |
| 14:41 | • Ticket [1873ea0ee4]: 3 changes artifact: 784f5a2068 user: sebres | |
| 13:57 | • Ticket [1873ea0ee4]: 3 changes artifact: 5f24443d5a user: tomkiti | |
| 13:46 | • New ticket [1873ea0ee4]. artifact: c3d0c8c99b user: sebres | |
open channel "nul" within non-main thread on windows (not-console application)
As I understand, first calls of `open "nul" w`, on Windows within new thread, wrap the open channel to the std-channels.
So second to fourth call (first time executed) get corresponding stdin, stdout and stderr.
This occurs only within not console application, that does not share standard channels (currently reproducible for tk, not for tclsh).
So as simplification it looks like:
set t [thread::create];
puts [join [thread::send $t {
set chs {}
time { lappend chs [open nul w] } 5;
foreach ch $chs { close $ch }
set chs
}] \n]
thread::release $t
will give one the output:file11dd288
stdin
stdout
stderr
file11d03f0
---
Original message from Timothy Tomkinson:
```
In wish 8.6.8 on Windows, the 2nd, 3rd, and 4th files that are opened within a thread return the channel names stdin, stdout, and stderr. This does not happen in the main thread, in tclsh 8.6.8, in wish 8.5.*, or on Linux.
For example, the following script writes the first 5 opened channel names to a log file:
The file c:/temp/log.txt will contain something like:
package require Thread
set tid [::thread::create]
::thread::send $tid {
set chan1 [open c:/temp/log.txt w]
set chan2 [open nul w]
set chan3 [open nul w]
set chan4 [open nul w]
set chan5 [open nul w]
puts $chan1 "chan1 = $chan1"
puts $chan1 "chan2 = $chan2"
puts $chan1 "chan3 = $chan3"
puts $chan1 "chan4 = $chan4"
puts $chan1 "chan5 = $chan5"
close $chan1
close $chan2
close $chan3
close $chan4
close $chan5
}
exit
```
chan1 = file303b0c0
chan2 = stdin
chan3 = stdout
chan4 = stderr
chan5 = file3033160
This happens when opening any file (including sockets), not just "nul".
I got it now, this belongs to "wrong" recognition of first empty standart channel slots here.
This construction assumes that if (stdinInitialized = 1, etc), first 3 channels should get mapped to initial empty std-channels among the thread-storage. Which is rather actually wrong for the case of non-console application, or some initialization process does not set correctly stdinInitialized, stdoutInitialized etc in such case.
The same in 8.5 (also mapped to stdin, stdout and stderr), excepting the channels get the names.
This is because of the fully-correct commit [c0b94338ed879e40]:
+ strcpy(tmp, "stdin");
+ strcpy(tmp, "stdout");
+ strcpy(tmp, "stderr");
But the real cause is entirely different - this is TclpGetDefaultStdChannel with not allowed duplication for std-handle, returned with GetStdHandle, so returns NULL from the Tcl_MakeFileChannel...
I'll fix it for all versions >= 8.5.
fixed for both versions now (8.5 [041bc74867] and >= 8.6 [6b38bf6d66]).