pipe with threads

Jan Pechanec jp at devnull.cz
Wed Dec 2 17:48:01 UTC 2009


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


More information about the freebsd-threads mailing list