Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Paul Pluzhnikov <ppluzhnikov@earthlink.net>
Subject: Re: fork() problem
Date: Fri, 30 Aug 2002 18:04:26 GMT	[thread overview]
Message-ID: <m3wuq8p7nj.fsf@salmon.parasoft.com> (raw)
In-Reply-To: roma-DF91D2.20413730082002@news.gamma.ru

Roman Prokhorov <roma@stalker.gamma.ru> writes:

> >   To  understand  the purpose of pthread_atfork, recall that
> >   fork(2) duplicates the whole memory space, including mutexes in
> >   their current locking state, but only the  calling  thread:  other
> >   threads  are  not  running  in the child process. Thus, if a mutex
> >   is locked by a thread other than the thread calling fork, that
> >   mutex will remain locked forever in the child process, possibly
> 
> Yes, but it becomes locked in parent process too !!!

It will be unlocked in the parent process as soon as
fork() is done.

> 
> >   blocking  the  execution  of  the  child  process. To avoid this,
> >   install handlers with pthread_atfork as follows: the prepare handler
> >   locks the global mutexes  (in  locking  order), and  the  parent
> >   and child handlers unlock them (in reverse order). Alternatively,
> >   prepare and parent can be set to NULL and child to a function that
> >   calls pthread_mutex_init on the  global mutexes.
> > 
> > Apparently Tru64 choose the first alternative ;-(
> > 
> > Cheers,
> 
> OK, what mutexes are locked by fgets? Are they documented anywhere?

It is unlikely that fgets needs other mutexes (it may need malloc
mutex at times). It is also unlikely that these mutexes are
documented anywhere.

Even if they were, you are missing the point:

    > How to make it to create all the files 
    > _while_ it's waiting for the input? 

which is that you *can't* reliably fork() multithreaded programs,
unless you wrote *all* the code [including libc]. Since you
did not write libc [and I hope you don't plan on it ;-], you just
can't fork().

Accept this fact, and move on to one of the other solutions.

Cheers,
-- 
In order to understand recursion you must first understand recursion.


      reply	other threads:[~2002-08-30 18:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-28 23:13 fork() problem Roman Prokhorov
2002-08-29  4:04 ` Paul Pluzhnikov
2002-08-29 15:00   ` Roman Prokhorov
2002-08-30  0:05     ` Paul Pluzhnikov
2002-08-30 12:28       ` Roman Prokhorov
2002-08-30 15:04         ` Paul Pluzhnikov
2002-08-30 16:41           ` Roman Prokhorov
2002-08-30 18:04             ` Paul Pluzhnikov [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox