From owner-freebsd-current@FreeBSD.ORG Thu Sep 18 17:35:43 2008 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8AD081065676 for ; Thu, 18 Sep 2008 17:35:43 +0000 (UTC) (envelope-from jille@quis.cx) Received: from smtp2.versatel.nl (smtp2.versatel.nl [62.58.50.89]) by mx1.freebsd.org (Postfix) with ESMTP id 001708FC15 for ; Thu, 18 Sep 2008 17:35:42 +0000 (UTC) (envelope-from jille@quis.cx) Received: (qmail 25251 invoked by uid 0); 18 Sep 2008 17:09:02 -0000 Received: from ip83-113-174-82.adsl2.static.versatel.nl (HELO istud.quis.cx) ([82.174.113.83]) (envelope-sender ) by smtp2.versatel.nl (qmail-ldap-1.03) with SMTP for < >; 18 Sep 2008 17:09:02 -0000 Received: from [192.168.1.4] (ille [192.168.1.4]) by istud.quis.cx (Postfix) with ESMTP id 450F35C1D; Thu, 18 Sep 2008 19:09:02 +0200 (CEST) Message-ID: <48D28B2D.90204@quis.cx> Date: Thu, 18 Sep 2008 19:09:01 +0200 From: Jille Timmermans User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: David Naylor References: <200809180631.47071.naylor.b.david@gmail.com> <1221744832.68732.4.camel@localhost> <200809181857.25872.naylor.b.david@gmail.com> In-Reply-To: <200809181857.25872.naylor.b.david@gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Tom Evans , freebsd-current@freebsd.org Subject: Re: FreeBSD deadlock (with fork?) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Sep 2008 17:35:43 -0000 David Naylor schreef: > On Thursday 18 September 2008 15:33:52 Tom Evans wrote: >> On Thu, 2008-09-18 at 06:31 +0200, David Naylor wrote: >>> Hi, >>> >>> I have a program that spawns a lot of subprocesses (with pipes open) from >>> multiple threads. The problem is the program often deadlocks, but not >>> consistently. Sometimes the program can run over 5 times to competition >>> without incidence and yet othertimes it locks within a few seconds. >> Do you create threads, which then fork(), or do you fork() and then create >> threads? > > I have many threads that then fork. (aka forking threads). If you fork, the child will only have one thread, the one that called fork(). The parent is left as is. (This prevents a lot of races; mostly in programs that fork() and execve()) > >> I think the former will not work.. > > Is there any reason for this and is this a FreeBSD limitation or a general > problem? I assume all fork()ing OS's will do this. > > The problem is that my program has to have threads (or something similar) > since it handles lots of IO bound processes concurrently so is there a > work-a-round for this problem? > > I could limit the forking to a single thread (which I tried and did not work) > but perhaps I need to have it fork from the master thread? Doesn't matter wrt the single-threaddedness of the child (which can create threads after being forked off) -- Jille > > One option I considered was forking a 'slave' program that then does all the > forking but that will become exceedingly complex (with the communication > between the 'slave' and the threads). > > Lastly, how does GUIs, such as Qt, handle forking since they are threaded and > some do fork? >> Cheers >> >> Tom > > Regards > > David