Hi karlgoethebier,
Update: Ah, the OP wants to read DATA independently. See tybalt89's solution.
Update: Currently, the following demos work on Unix platforms with IO::FDPass: automatically loaded by MCE::Shared if present in Perl. The next update to MCE::Shared on CPAN will support reading from the DATA handle without involving IO::FDPass and work on Windows including Cygwin.
MCE::Shared works similarly with threads and MCE::Hobo.
threads demonstration
use strict;
use warnings;
use threads;
use MCE::Shared;
mce_open my $shared_fh, '<', \*DATA;
async {
print "Start Thread\n";
while (<$shared_fh>) {
print "T: $_"; sleep 1;
}
print "Stop Thread\n";
};
print "Start Parent\n";
while (<$shared_fh>) {
print "P: $_"; sleep 1;
}
print "Stop Parent\n";
$_->join for threads->list;
__DATA__
a
b
c
d
e
f
g
h
i
j
MCE::Hobo demonstration
use strict;
use warnings;
use MCE::Hobo;
use MCE::Shared;
mce_open my $shared_fh, '<', \*DATA;
mce_async {
print "Start Child\n";
while (<$shared_fh>) {
print "C: $_"; sleep 1;
}
print "Stop Child\n";
};
print "Start Parent\n";
while (<$shared_fh>) {
print "P: $_"; sleep 1;
}
print "Stop Parent\n";
MCE::Hobo->waitall;
__DATA__
a
b
c
d
e
f
g
h
i
j
Regards, Mario
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|