#!/opt/perl/bin/perl use strict; use threads; use MCE::Mutex; use MCE::Shared; open my $fh, '|-', 'gzip > test.txt.gz'; foreach (1..10000) { print {$fh} sprintf("%05d%s\n", $_, ('abc123' x 10)); } close $fh; mce_open $fh,'-|','gzip -cd test.txt.gz' or die "Failed to uncompress: $!\n"; $| = 1; my @threads = (); my $mutex = MCE::Mutex->new(); foreach (1..3) { push @threads, threads->create(\&test); } $_->join() foreach @threads; close $fh; print "\n"; sub test { my $tid = threads->tid(); my $line; while(1) { threads->yield(); $mutex->lock(); $line = <$fh> or last; print "Thread $tid ".$line; $mutex->unlock(); } $mutex->unlock; }