Of course the parent must wait on its child. However, before that the
input of the pipe on which the child reads must be closed by the
parent, otherwise the child will wait indefinitely for new integers from the
parent. This leads to a deadlock (closing the channel empties the
buffer before closing the corresponding descriptor, therefore no data
is lost). Concretely, the line 10 of the sieve
function needs to be replaced by:
Accordingly, we enclose the
lines 12–16 of the
filter
function (represented by ...
below) with the
following lines: