From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22379 invoked from network); 9 Jan 2000 01:00:30 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 9 Jan 2000 01:00:30 -0000 Received: (qmail 22901 invoked by alias); 9 Jan 2000 01:00:14 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2856 Received: (qmail 22883 invoked from network); 9 Jan 2000 01:00:13 -0000 From: "Bart Schaefer" Message-Id: <1000109005928.ZM29901@candle.brasslantern.com> Date: Sun, 9 Jan 2000 00:59:28 +0000 In-Reply-To: <3874B2DD.A80FBAFC@u.genie.co.uk> Comments: In reply to Oliver Kiddle "Re: Prompt expansion, multi-job for" (Jan 6, 3:21pm) References: <20000106194432.A488@bozar.ihug.com.au> <3874847D.A2ED4AE3@u.genie.co.uk> <20000106151942.A18295@picard.franken.de> <3874B2DD.A80FBAFC@u.genie.co.uk> X-Mailer: Z-Mail (5.0.0 30July97) To: Oliver Kiddle , zsh-users@sunsite.auc.dk Subject: Re: Prompt expansion, multi-job for Cc: =?iso-8859-1?Q?Thomas_K=F6hler?= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 6, 3:21pm, Oliver Kiddle wrote: } Subject: Re: Prompt expansion, multi-job for } } That's certainly one way. I seem to remember seeing someone else's } solution using a co-routine at some point (Bart maybe?). You must be thinking of this. It's from a thread with the subject "Running N jobs from M all the time". function run_parallel { # Runs N copies of command at once until M copies have run. emulate -L zsh if (( $# < 3 )); then print "usage: run_parallel N M command [args ...]" >&2 return 1 fi integer N=$1 M=$2 shift 2 if ((M <= N)); then repeat $M do $==* & done wait else # Set up a loop to read and write one byte at a time. This # semaphores between the parallel children and the parent zsh. # It's important to pass exactly one byte here and not rely on # reading complete lines, lest a race condition develop. # Unfortunately, a race still can occur, it's just less likely. # Maybe SMP systems are better about multiple writers on one FD? coproc while ((--M > 0)) && read -u0k; do print -n .; done # Start the first N children repeat $N do ((--M)) { $==* ; print -np . } & done # Wait for the semaphore from each child and start another as # soon as we get it, up to M children. while ((--M > 0)) && read -pk; do { $==* ; print -np . } & done # Wait for the last N semaphores. repeat $N do read -pk; done fi return $? } -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com