Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Sep 2008 17:14:39 -0400 (EDT)
From:      Daniel Eischen <deischen@freebsd.org>
To:        David Naylor <naylor.b.david@gmail.com>
Cc:        freebsd-current@freebsd.org, Julian Elischer <julian@elischer.org>
Subject:   Re: FreeBSD deadlock (with fork?)
Message-ID:  <Pine.GSO.4.64.0809181708530.20788@sea.ntplx.net>
In-Reply-To: <200809182122.08221.naylor.b.david@gmail.com>
References:  <200809180631.47071.naylor.b.david@gmail.com> <48D2807A.1050106@elischer.org> <200809182122.08221.naylor.b.david@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 18 Sep 2008, David Naylor wrote:

> On Thursday 18 September 2008 18:23:22 you wrote:
>> 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.
>>
>> you sent this to -current. Is it in -current? (we fixed something like
>> this some months back in current and 7)
>
> -current cvsuped about Tuesday.
>
>> do your post-fork processes do an exec?  according to the spec they
>> should.
>
> Yes, they do.  See the other replies...
>
>> if any of your threads other than the one that did the fork ho;ds any
>> mutex at teh time of fork then your process will hang. If they hold a
>> umtx (between processes) then everything will hang.
>
> Yes, the system does make use of mutexes.  The forking thread never holds a
> mutex but other threads could hold a mutex.  This would explain the problem.
> Is there any way to get around it (i.e. make sure no mutexes are held when a
> fork is called?)

You can hold mutexes while forking, you just can't rely on
their state in any child process.

There is also pthread_atfork().

-- 
DE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0809181708530.20788>