so I changed the name.

Hm. An unfortunate but coincidental 'random' choice of name? (Google to understand what I mean.)

So the million dollar question that I'm asking is what would a <$handle> in thread A stop a threads->new() from starting thread C & D from thread B?

To be able to answer that question with any certainty, I'd have to be able to run code that demonstrates the problem with my debugger and other tools. And a part of that would be using the actual executable to see (for example) whether it is buffering its output.

I'd also have to see what is going on inside the thread that is 'failing to start'. And clearer definition of 'failing to start' wouldn't go amiss.

However, let me speculate. Does the thread that fails to start attempt to either read or write to the same socket ($handle)?

Rational: using readline (including via the diamond (<>) operator), will block, even on a socket set non-blocking, until a newline is read. That's the basic definition of readline().

And, you cannot (under win32 at least), both read from and write to the same socket concurrently on different threads. The OS will serialise concurrent access attempts.

And if the external process is buffering it's output, then even if every line it writes is always terminated with a newline, the effect of buffering means that when the buffer size, (probably 4096 bytes), is eventually reached, several lines--usually including an incomplete, unterminated last line--will be flushed as a single output.

If the receiving end of the pipe is doing readlines, then it will block waiting for that incomplete line to be completed. But, the external process may take a while to (or indeed never), fill another buffer load, and so the receiving end just sits and waits. If the other threads you are starting then attempt to write to the socket, they will block until the reading thread completes it's readline. Which may never happen.

When you set sockets non-blocking, you should avoid buffered IO. Instead use either sysread or recv and syswrite or send.

That's all speculation (given the absence of good information or code to test), and may only be applicable to win32


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^14: Forks, Pipes and Exec (file descriptors) by BrowserUk
in thread Forks, Pipes and Exec by diabelek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.