From owner-freebsd-threads@FreeBSD.ORG Wed Dec 2 17:48:01 2009 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DEC9A106566B for ; Wed, 2 Dec 2009 17:48:01 +0000 (UTC) (envelope-from jp@devnull.cz) Received: from smtp2.vol.cz (smtp2.vol.cz [195.250.128.75]) by mx1.freebsd.org (Postfix) with ESMTP id 9E0E18FC17 for ; Wed, 2 Dec 2009 17:48:01 +0000 (UTC) Received: from 167.col.prg.mynet.cz (167.col.prg.mynet.cz [195.122.208.167]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.volny.cz (Postfix) with ESMTPS id 803EE289E7; Wed, 2 Dec 2009 18:30:38 +0100 (CET) Date: Wed, 2 Dec 2009 18:28:11 +0100 (CET) From: Jan Pechanec X-X-Sender: janp@rax.devnull.cz To: Gennady Proskurin In-Reply-To: <20091202165647.GA1944@gpr.nnz-home.ru> Message-ID: References: <20091202165647.GA1944@gpr.nnz-home.ru> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: freebsd-threads@freebsd.org Subject: Re: pipe with threads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2009 17:48:01 -0000 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 http://www.devnull.cz