[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Examples of concurrent coproc usage?
From: |
Chet Ramey |
Subject: |
Re: Examples of concurrent coproc usage? |
Date: |
Mon, 1 Apr 2024 15:24:07 -0400 |
User-agent: |
Mozilla Thunderbird |
On 3/14/24 5:58 AM, Carl Edquist wrote:
But you can create a deadlock without doing anything fancy.
Well, *without multi-coproc support*, here's a simple wc example; first
with a single coproc:
$ coproc WC { wc; }
$ exec {WC[1]}>&-
$ read -u ${WC[0]} X
$ echo $X
0 0 0
This works as expected.
But if you try it with a second coproc (again, without multi-coproc
support), the second coproc will inherit copies of the shell's read and
write pipe fds to the first coproc, and the read will hang (as described
above), as the first coproc doesn't see EOF:
$ coproc WC { wc; }
$ coproc CAT { cat; }
$ exec {WC[1]}>&-
$ read -u ${WC[0]} X
# HANGS
But, this can be observed even before attempting the read that hangs.
Let's see if we can tackle these one at a time. This seems like it would be
pretty easy to fix if a coproc closed the fds corresponding to an existing
coproc in the child after the fork. That wouldn't really change anything
regarding how scripts have to manually manage multiple coprocs, but it
will prevent the shell from hanging.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- Re: Examples of concurrent coproc usage?,
Chet Ramey <=