Re: multi-threaded compiling
Mischa Baars <[email protected]> Mon, 11 Mar 2024 22:19:26 +0100
| Newsgroups | gmane.comp.shells.bash.bugs,gmane.comp.gnu.make.general |
|---|---|
| Message-ID | <CA+b5WFE07fcM7coQzcmjBy2S3Lqdv9HgdDq=MfCf5JrnV9mriw@mail.gmail.com> |
On Mon, 11 Mar 2024, 21:08 Kerin Millar, <[email protected]> wrote: > On Mon, 11 Mar 2024 15:36:48 -0400 > Greg Wooledge <[email protected]> wrote: > > > > On Mon, Mar 11, 2024, 20:13 Mischa Baars <[email protected] > > > > > wrote: > > > > > > > Also I don't think that gives you an exit status for each 'exit $i' > > > > started. I need that exit status. > > > > "wait -n" without a PID won't help you, then. You don't get the PID or > > job ID that terminated, and you don't get the exit status. It's only > > It does convey the exit status. > > > of interest if you're trying to do something like "run these 100 jobs, > > 5 at a time" without storing their exit statuses. > > The pid can be obtained with the -p option, as of 5.1. Below is a > synthetic example of how it might be put into practice. > > #!/bin/bash > > declare -A job_by status_by > max_jobs=4 > jobs=0 > > wait_next() { > local pid > wait -n -p pid > status_by[$pid]=$? > How exactly is this indexing implemented internally? Does a first number on index n take m bits (using a linked list) or does it take n * m bits (using realloc(3))? unset -v 'job_by[$pid]' > } > > worker() { > sleep "$(( RANDOM % 5 ))" > exit "$(( RANDOM % 2 ))" > } > > for (( i = 0; i < 16; ++i )); do > (( jobs++ < max_jobs )) || wait_next > worker & job_by[$!]= > done > > while (( ${#job_by[@]} )); do > wait_next > done > > declare -p status_by > > -- > Kerin Millar > >