On 11/26/2008 11:32 PM, Andrew Clarke wrote:
On Thu, 27 Nov 2008 15:24, Ron Isaacson wrote:
#!/bin/ksh
while read task; do
$task &
while [[ `jobs | wc -l` -ge 3 ]]; do sleep 1; done
done
while [[ `jobs | wc -l` -gt 0 ]]; do sleep 1; done
hmmm, or something along the lines of
let n=0
let lim=3
while read task; do
$task &
if [[ $((++n)) -ge $lim ]]; then
wait
let n--
fi
done
while [[ $((n--)) -gt 0 ]]; do
wait
done
only because I dislike using sleep in any task just to avoid counting or
waiting properly. Have I got my pre-fix and post-fix operators on the right
side both times?
Warning/Apology: the following commentary has nothing to do with parallism.
I guess old habits die hard, but I still wonder why it is that 15 (or is
it 20?) years after
David Korn added native integer arithmetic and the math expression (( ))
to ksh,
folks still use -eq, -ge, -gt and so on inside [[ ]] or worse, [ ] .
You have the integer variables defined with let, why not use them as
integers
and avoid the unnecessary num-to-string-to-num conversions, the extra
$var derefs,
and improve the readability? OK, readability may be subjective, but we
all remember
our basic algebraic expressions, right? :-)
Regarding post-fix/pre-fix operations, I am a stalwart fan of the KISS
principle,
thus I avoid such dependencies whenever possible so that I don't have to
tax my brain
with remembering extensive precedence of operators rules.
Therefore I gently submit these syntax changes for your code above:
integer n=0
integer lim=3
(( n++ ))
if (( n >= lim )) ; then
wait
(( n-- ))
...
while (( n > 0 )) ; do
wait
(( n-- ))
...
At least it's nice to see that many people have stopped using [ ] in
favor of [[ ]] :-)
Cheers,
Mario
Korn Shell Syntactevangelist
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users