Just another Perl shrine | |
PerlMonks |
Re^6: threads on Windowsby gone2015 (Deacon) |
on Feb 21, 2009 at 13:00 UTC ( [id://745527]=note: print w/replies, xml ) | Need Help?? |
Have you ever heard of the concept of a reduced testcase? I'm sorry... when I did the work I was trying to find what was going "wrong" with the OP... so I aimed to disturb the underlying code as little as possible. But with a litle more time on my hands, it being Saturday... see below. Did you see my post where I mentioned that "the OS serialises read and write accesses to console devices."? I did, thank you. And, as I said, when I tried a file attached to STDIN the "problem" went away. So, yes, the effect appears to be peculiar to the console. However:
So... the serialization of console read and write access doesn't appear to be the issue. Have you consider the effect of all your verbose logging, and tracing, and "determining the state of STDIN" is having upon the outcome you are seeking to establish? I have. Which is why the trace is gathered in memory and not output until the end. It does introduce a small critical region in the trace gatherer... but that should only affect the progress of the threads (which is arbitrary in any case) when they are runnable. So if my means of observing the problem has affected it, I'm blessed if I can see how. I'm not sure what you mean by "determining the state of STDIN"... but if you mean the test to see if STDIN was open/closed after starting the "Terminal Watcher": then I can tell you that the main result is the same with or without that piece of code. Reduced test case code: which on my uni-processor, Windows XP, Perl 5.10.0, gives: Z:\>perl threads_r.pl 12345678901234567890 @ 0.000006: main thread start @ 0.014843: STDIN thread started @ 0.015520: about to start child thread @ 9.814112: STDIN thread received input @ 9.824127: child thread ran @ 9.834141: about to collect results @ 9.834517: main thread completesbut if the main thread closes STDIN: Z:\>perl threads_r.pl close 12345678901234567890 @ 0.000004: main thread start @ 0.008159: closed STDIN @ 0.008267: STDIN thread started @ 0.008845: about to start child thread @ 0.017748: child thread ran @ 0.022810: about to collect results @ 10.725422: STDIN thread received input @ 10.735437: main thread completes(where the italics is me pecking at the keyboard to introduce a delay...) FWIW, here's what my Linux box (also uni-processor, Perl 5.10.0) does: [GMCH@hestia ~]$ perl threads_r.pl 012345678901234567890 @ 0.000012: main thread start @ 0.008300: STDIN thread started @ 0.008525: about to start child thread @ 0.024331: child thread ran @ 0.028648: about to collect results @ 11.298085: STDIN thread received input @ 11.298319: main thread completesand closing STDIN makes no difference. My hypothesis is: when creating the child thread the main thread is blocked because whatever "clones" STDIN cannot do so while some other thread is waiting on it -- where STDIN is attached to the console. I can see how that could be related to the serialisation of access to the console device. Nevertheless, it is a bit of a surprise. Happily, closing STDIN does not block and does close the handle -- so there is a work around.
In Section
Seekers of Perl Wisdom
|
|