.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Parallel::Pipes 3pm" .TH Parallel::Pipes 3pm 2026-06-18 "perl v5.42.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Parallel::Pipes \- parallel processing using pipe(2) for communication and synchronization .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Parallel::Pipes; \& \& my $pipes = Parallel::Pipes\->new(5, sub ($task) { \& # this is a worker code \& my $result = do_work($task); \& return $result; \& }); \& \& my $queue = Your::TaskQueue\->new; \& # wrap Your::TaskQueue\->get \& my $get; $get = sub ($queue) { \& if (my @task = $queue\->get) { \& return @task; \& } \& if (my @written = $pipes\->is_written) { \& my @ready = $pipes\->is_ready(@written); \& $queue\->register($_\->read) for @ready; \& return $queue\->$get; \& } else { \& return; \& } \& }; \& \& while (my @task = $queue\->$get) { \& my @ready = $pipes\->is_ready; \& $queue\->register($_\->read) for grep $_\->is_written, @ready; \& my $min = List::Util::min($#task, $#ready); \& for my $i (0..$min) { \& # write tasks to pipes which are ready \& $ready[$i]\->write($task[$i]); \& } \& } \& \& $pipes\->close; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBNOTE\fR: Parallel::Pipes provides low\-level interfaces. If you are interested in using Parallel::Pipes, you may want to look at Parallel::Pipes::App instead, which provides more friendly interfaces. .PP Parallel processing is essential, but it is also difficult: .IP "How can we synchronize our workers?" 4 .IX Item "How can we synchronize our workers?" More precisely, how to detect our workers are ready or finished. .IP "How can we communicate with our workers?" 4 .IX Item "How can we communicate with our workers?" More precisely, how to collect results of tasks. .PP Parallel::Pipes tries to solve these problems with \f(CWpipe(2)\fR and \f(CWselect(2)\fR. .PP App::cpm, a fast CPAN module installer, uses Parallel::Pipes. Please look at App::cpm or eg directory for real world usages. .SH "ARTIFACT ATTESTATIONS" .IX Header "ARTIFACT ATTESTATIONS" GitHub Artifact Attestations are generated for release tarballs uploaded to CPAN. If you care about provenance for the uploaded tarballs, see: .PP .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2016 Shoichi Kaji .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.