wait(1) with no operands waits for all jobs to complete

On Thu, 27 Nov 2008 01:56:41 -0500 Mario DeFazio wrote:
> 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

> --Boundary_(ID_l26hH9fAQIvmpIU8f2lYrQ)
> Content-type: text/html; charset=ISO-8859-1
> Content-transfer-encoding: 7BIT

> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
>   <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
>   <title></title>
> </head>
> <body bgcolor="#ffffff" text="#000000">
> <br>
> On 11/26/2008 11:32 PM, Andrew Clarke wrote:
> <blockquote cite="mid:[EMAIL PROTECTED]"
>  type="cite">
>   <pre wrap="">On Thu, 27 Nov 2008 15:24, Ron Isaacson wrote:
>   </pre>
>   <blockquote type="cite">
>     <pre wrap="">  #!/bin/ksh

>   while read task; do
>     $task &amp;
>     while [[ `jobs | wc -l` -ge 3 ]]; do sleep 1; done
>   done

>   while [[ `jobs | wc -l` -gt 0 ]]; do sleep 1; done

>     </pre>
>   </blockquote>
>   <pre wrap=""><!---->
> hmmm, or something along the lines of

>     let n=0
>     let lim=3
>     while read task; do
>         $task &amp;
>         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?

>   </pre>
> </blockquote>
> <tt><br>
> Warning/Apology: the following commentary has nothing to do with
> parallism.<br>
> <br>
> I guess old habits die hard, but I still wonder why it is that 15 (or
> is it 20?) years after<br>
> David Korn added native integer arithmetic and the math expression ((
> )) to ksh,<br>
> folks still use -eq, -ge,&nbsp; -gt and so on inside [[ ]] or worse,&nbsp; [ 
> ] .<br>
> You have the integer variables defined with let, why not use them as
> integers<br>
> and avoid the unnecessary num-to-string-to-num conversions, the extra
> $var derefs,<br>
> and improve the readability? OK, readability may be subjective, but we
> all remember<br>
> our basic algebraic expressions, right? :-) <br>
> <br>
> Regarding post-fix/pre-fix operations, I am a stalwart fan of the KISS
> principle,<br>
> thus I avoid such dependencies whenever possible so that I don't have
> to tax my brain<br>
> with remembering extensive precedence of operators rules.<br>
> <br>
> Therefore I gently submit these syntax changes for your code above:<br>
> <br>
> integer n=0<br>
> integer lim=3<br>
> (( n++ ))<br>
> if (( n &gt;= lim )) ; then<br>
> &nbsp;&nbsp;&nbsp; wait<br>
> &nbsp;&nbsp;&nbsp; (( n-- ))<br>
> ...<br>
> <br>
> while (( n &gt; 0 )) ; do<br>
> &nbsp;&nbsp;&nbsp; wait<br>
> &nbsp;&nbsp;&nbsp; (( n-- ))<br>
> ...<br>
> <br>
> At least it's nice to see that many people have stopped using [ ]&nbsp; in
> favor of [[ ]] :-)<br>
> <br>
> Cheers,&nbsp; <br>
> &nbsp;&nbsp; Mario<br>
> &nbsp;&nbsp; Korn Shell Syntactevangelist <br>
> <br>
> <br>
> </tt>
> </body>
> </html>

> --Boundary_(ID_l26hH9fAQIvmpIU8f2lYrQ)--

> --===============0306886931==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline

> _______________________________________________
> ast-users mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-users

> --===============0306886931==--

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to