Date: Wed, 2 Dec 2009 18:28:11 +0100 (CET) From: Jan Pechanec <jp@devnull.cz> To: Gennady Proskurin <gprspb@mail.ru> Cc: freebsd-threads@freebsd.org Subject: Re: pipe with threads Message-ID: <alpine.BSF.2.00.0912021822370.66939@rax.devnull.cz> In-Reply-To: <20091202165647.GA1944@gpr.nnz-home.ru> References: <20091202165647.GA1944@gpr.nnz-home.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2 Dec 2009, Gennady Proskurin wrote: >I use usual scenario for writing data to stdin of some other program: >1. pipe, fork >2. Child: dup2, exec. Parent: write > >When my program is single-threaded (or may be multithreaded, with only >one thread running this scenario), all works fine. >But when this scenario executed concurently by many threads, the reading >process sometimes doesn't see, that pipe was closed and reading process >is stuck in read() (piperd wchan), and write process is stuck in waitpid. > >Is it a bug somewhere or I missing something? Gennady, I think there is a bug in your code. While a forked process has just the thread that called fork(), the file descriptor table is the exact copy. So, you may end up with multiple processes, each possibly having an open end of a few writing ends of pipes used in another processes. So, as long there are potentically more writers, you can't get EOF. J. -- Jan Pechanec <jp (at) devnull (dot) cz> http://www.devnull.cz
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.0912021822370.66939>