in reply to Re^3: Using Select and pipes to communicate with threads
in thread Using Select and pipes to communicate with threads
Your second link has nothing to do with conventional pipes at all, it states
Instead of passing a handle to the object back to the parent so that it can control it, try giving the parent a shared variable that indicates what it wants the child to do to the object.
Neither of these show how to setup conventional pipes to threads, let alone show how to read output from many threads/pipes in a simple select loop.
Sure, there are many ways to do communication between threads and parent, but neither of your examples show how to use IO::Select to monitor multiple threads whose output is directly fed to pipes, an even more precise, an IO::Pipe object.
Furthermore, I find your code overly complicated, for example you do
Ugh!!!# save STDOUT open(my $STDOUT_ORIG, ">&", \*STDOUT) or die; # connect TO_CHILD_PROC with CHILD_PROC pipe(CHILD_PROC, TO_CHILD_PROC); # change STDOUT to TO_CHILD_PROC # --> STDOUT of child process is set to TO_CHILD_PROC and # this is connected via pipe with CHILD_PROC open(STDOUT, ">&", \*TO_CHILD_PROC);
When all that is needed is
# in thread my $wh = $pipe->writer; $wh->autoflush(1); print $wh "whatever \n" ;
Sorry, but you have not shown any link of yours that uses IO::Select and IO::Pipe in such a clearcut and simple manner, for monitoring multiple threads with 1 loop, as my script does. So I feel it is my right to defend it's virtue and put in Cool Uses for Perl, so others can use the simple technique. Even googling for "perl threads pipe mkfifo" yields few real scripts, and NONE of them combine IO::Select with the simplicity of IO::Pipe.
So sorry BrowserUk, this time your blusterous hot air dosn't fill the balloon.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Using Select and pipes to communicate with threads
by BrowserUk (Patriarch) on Sep 02, 2011 at 16:36 UTC | |
by zentara (Cardinal) on Sep 02, 2011 at 16:44 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2011 at 16:49 UTC |