zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: zsh-users@sunsite.auc.dk
Cc: "Thomas Köhler" <jean-luc@picard.franken.de>
Subject: Re: Prompt expansion, multi-job for
Date: Thu, 06 Jan 2000 15:21:01 +0000	[thread overview]
Message-ID: <3874B2DD.A80FBAFC@u.genie.co.uk> (raw)
In-Reply-To: <20000106151942.A18295@picard.franken.de>

Thomas Köhler wrote:

> Well, bad idea if you have a few hundred wavs :)
> 
> > The trouble with this is that it will attempt to run all the l3encs
> > together. If you have say 4 processors, it may be most efficient to run
> > a maximum of 4 l3encs at once. This would be a bit messy to implement in
> > Zsh (compared to something like Ada) but can be done.
> 
> Well - let's try something like this:

That's certainly one way. I seem to remember seeing someone else's
solution using a co-routine at some point (Bart maybe?). Here is my
method which I think is quite simple:

trap '(( jobs=jobs-1 ))' CHLD

for i in 10 9 2 3 1 7 1 2 4; do
  while (( jobs >= 4 )); do
    :
  done
   
  echo Running sleep $i.
  (( jobs=jobs+1 ))
  sleep $i &
done
 
echo Wait for last job to finish
wait

For the original problem, you would want to replace sleep with l3enc and
the list of numbers with your glob for .wav files. I just thought that
this demonstrates it better. You might also want to use a 'sleep 1'
instead of ':' so that the while loop loops more slowly.

In theory you could have problems if the increment and decrement for
$jobs didn't run atomicly and ran at the same time but this is hardly a
safety-critical system and with jobs as long as l3enc, I'd doubt it
would happen. At worst $jobs would end up a little out so you'd have
more or less concurrent jobs.

Other jobs finishing might also mess this up but you can always avoid
that by running it all in a sub-shell.

Anyone else got any other solutions (maybe using co-routines, fifos or
something)?

Oliver


  reply	other threads:[~2000-01-06 15:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-06  8:44 Andre Pang
2000-01-06 12:03 ` Oliver Kiddle
2000-01-06 14:19   ` Thomas Köhler
2000-01-06 15:21     ` Oliver Kiddle [this message]
     [not found]       ` <14452.47479.5744.410474@gargle.gargle.HOWL>
2000-01-06 17:47         ` Oliver Kiddle
2000-01-09  0:59       ` Bart Schaefer
2000-01-06 14:54   ` Andre Pang
2000-01-06 12:44 ` Andrej Borsenkow
2000-01-06 14:46   ` Andre Pang
2000-01-06 20:18 ` Peter Stephenson
2000-01-06 11:41 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3874B2DD.A80FBAFC@u.genie.co.uk \
    --to=opk@u.genie.co.uk \
    --cc=jean-luc@picard.franken.de \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).