Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/Synchronous-concurrency/Perl/synchronous-concurrency.pl
Normal file
33
Task/Synchronous-concurrency/Perl/synchronous-concurrency.pl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use threads;
|
||||
use Thread::Queue qw();
|
||||
|
||||
my $q1 = Thread::Queue->new;
|
||||
my $q2 = Thread::Queue->new;
|
||||
|
||||
my $reader = threads->create(sub {
|
||||
my $q1 = shift;
|
||||
my $q2 = shift;
|
||||
|
||||
open my $fh, '<', 'input.txt';
|
||||
$q1->enqueue($_) while <$fh>;
|
||||
close $fh;
|
||||
$q1->enqueue(undef);
|
||||
|
||||
print $q2->dequeue;
|
||||
}, $q1, $q2);
|
||||
|
||||
my $printer = threads->create(sub {
|
||||
my $q1 = shift;
|
||||
my $q2 = shift;
|
||||
|
||||
my $count;
|
||||
while (my $line = $q1->dequeue) {
|
||||
print $line;
|
||||
$count++;
|
||||
};
|
||||
|
||||
$q2->enqueue($count);
|
||||
}, $q1, $q2);
|
||||
|
||||
$reader->join;
|
||||
$printer->join;
|
||||
Loading…
Add table
Add a link
Reference in a new issue