FreeBSD deadlock (with fork?)
Daniel Eischen
deischen at freebsd.org
Thu Sep 18 17:13:21 UTC 2008
On Thu, 18 Sep 2008, David Naylor wrote:
> 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).
>
>>
>> I think the former will not work..
>
> Is there any reason for this and is this a FreeBSD limitation or a general
> problem?
No, the former will work. You can fork() from threads, only as long
as your forked processes only call async-signal-safe functions or
some form of exec(). For instance, you can't fork and then create
new threads from that child process. If you are not immediately
exec()'ing from the child process, then you have to be careful
and only use async-signal-safe functions.
Remember that you have multiple threads in the parent, so the
state of libthr, libc, etc may be inconsistent in a child
process.
--
DE
More information about the freebsd-current
mailing list