bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi-threaded compiling


From: Mischa Baars
Subject: Re: multi-threaded compiling
Date: Tue, 12 Mar 2024 13:30:05 +0100

On Tue, Mar 12, 2024 at 12:19 PM Greg Wooledge <greg@wooledge.org> wrote:

> On Tue, Mar 12, 2024 at 10:33:36AM +0100, Mischa Baars wrote:
> > bash -c 'set +m; seconds=1; for (( i=0;i<32;i++ )); do exit ${i} & done;
> > sleep ${seconds}; for (( i=0;i<32;i++ )); do wait -p pid; e=${?}; echo
> > "$(printf %3u ${i}) pid ${pid} exit ${e}"; done;'
>
> "wait -p pid" is not correct here.  In that command, pid is an output
> variable, and you have not specified any process IDs to wait for -- so
> wait is going to wait for *all* of the children to finish, and you'll
> get zero as the exit status:
>

These are the two waits I'm now using:

wait ${pid[${i}]};
wait -np pid;

Which gives the following two lines to execute either from script or from
makefile:

script:

seconds=5; for (( i=0;i<32;i++ )); do exit ${i} & pid[${i}]=${!}; done;
sleep ${seconds}; for (( i=0;i<32;i++ )); do wait ${pid[${i}]}; e=${?};
echo "$(printf %3u ${i}) pid ${pid[${i}]} exit ${e}"; done;
seconds=5; for (( i=0;i<32;i++ )); do exit ${i} &                 done;
sleep ${seconds}; for (( i=0;i<32;i++ )); do wait -np pid;      e=${?};
echo "$(printf %3u ${i}) pid ${pid} exit ${e}";       done; #!!! script
only !!!

makefile:

seconds=5; for (( i=0;i<32;i++ )); do exit $${i} & pid[$${i}]=$${!}; done;
sleep $${seconds}; for (( i=0;i<32;i++ )); do wait $${pid[$${i}]}; e=$${?};
echo "$$(printf %3u $${i}) pid $${pid[$${i}]} exit $${e}"; done;
seconds=5; for (( i=0;i<32;i++ )); do exit $${i} &                   done;
sleep $${seconds}; for (( i=0;i<32;i++ )); do wait -np pid;        e=$${?};
echo "$$(printf %3u $${i}) pid $${pid} exit $${e}";        done; #???
script only ???

The first executes correctly from both the script and the Makefile. The
second only executes correctly from script.


> $ help wait
>     [...]
>
>     Waits for each process identified by an ID, which may be a process ID
> or a
>     job specification, and reports its termination status.  If ID is not
>     given, waits for all currently active child processes, and the return
>     status is zero.  If ID is a job specification, waits for all processes
>     in that job's pipeline.
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]