Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^14: Forks, Pipes and Exec (file descriptors)

by BrowserUk (Patriarch)
on Nov 12, 2008 at 21:39 UTC ( [id://723297]=note: print w/replies, xml ) Need Help??


in reply to Re^13: Forks, Pipes and Exec (file descriptors)
in thread Forks, Pipes and Exec

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found