fork vs fork1 on 2.6 MT app

fork vs fork1 on 2.6 MT app

Post by anra.. » Thu, 15 Jul 1999 04:00:00



Hi,

   Can somebody tell me the differences between
fork and fork1 on solaris 2.6 in a multi threaded
app using pthreads. The fork/fork1 man page is not
very clear.

regards
Ranganath

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

fork vs fork1 on 2.6 MT app

Post by anra.. » Thu, 15 Jul 1999 04:00:00


Hi,

   I thought that I should give some more info on why I need this info.
We have a MT app(pthreads). One of the threads does a fork1. The child
process does a malloc before it does an exec. Sometimes the the call to
fork1 does not return. So at this point we have two of our processes
running. If I attach the child process through dbx and check I find that
it is stuck in malloc. I have included below the relavent lines of the
trace. The child is stuck when it is trying to acquire a lock.

   Going through the man pages of fork/fork1 and pthread_atfork I
concluded that all the libraries that use locks need to call
pthread_atfork in their .init section. These man pages say that this
needs to be done to prevent any deadlocks in the child. I can probably
assume that the library supplying malloc (libc ?) is doing this
correctly.

   Earlier our code would actually use fork and not fork1, but we faced
some other probs with this and found that using fork1 solved our
problem. Now we are having the above problem using fork1. From the man
page I do not find any difference between fork & fork1 in a MT app using
pthreads.

   So can anybody tell me the differences between the two calls in such
an app. I cannot post any code as its too big and I have not tried to
simulate the problem in a sample app.

regards
Ranga

   [1] _lwp_sema_wait(0xee305e80, 0x1, 0x0, 0x0, 0xff00, 0xff), at
0xee9396f0
  [2] _park(0xee305de0, 0xee305e80, 0x0, 0xee305e5c, 0xee305e58,
0xee305e54), at 0xef24776c
  [3] _mutex_adaptive_lock(0xee9a6600, 0x4c00, 0xef265250, 0x1, 0x4d58,
0xfffeffff), at 0xef2487b0
  [4] _mutex_lock(0xee9a6600, 0xef265250, 0x0, 0x0, 0x0, 0x0), at
0xef2484f8
  [5] malloc(0x15, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xee945a40

regards
Ranganath



> Hi,

>    Can somebody tell me the differences between
> fork and fork1 on solaris 2.6 in a multi threaded
> app using pthreads. The fork/fork1 man page is not
> very clear.

> regards
> Ranganath

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

fork vs fork1 on 2.6 MT app

Post by Roger A. Faulkn » Fri, 16 Jul 1999 04:00:00



>Hi,

>   Can somebody tell me the differences between
>fork and fork1 on solaris 2.6 in a multi threaded
>app using pthreads. The fork/fork1 man page is not
>very clear.

The pthread3(3T) man page tells you that fork() is fork1()
for a -lpthread process.  (They are different for -lthread).

So for an app using pthreads, there is no difference.

Roger Faulkner

 
 
 

fork vs fork1 on 2.6 MT app

Post by Casper H.S. Dik - Network Security Engine » Fri, 16 Jul 1999 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>   Can somebody tell me the differences between
>fork and fork1 on solaris 2.6 in a multi threaded
>app using pthreads. The fork/fork1 man page is not
>very clear.

What's so unclear about:

     The  fork()  function  duplicates  all  the   threads   (see
     thr_create(3T))  and LWPs in the parent process in the child
     process. The fork1() function duplicates  only  the  calling
     thread (LWP) in the child process.

  POSIX Threads
     The following are the fork() semantics in programs that  use
     the  POSIX  threads  API rather than the Solaris threads API
     (programs linked with -lpthread, whether or not linked  with
     -lthread):

     The call to fork() is like a call to  fork1(), which  repli-
     cates only the calling thread. There is no call that forks a
     child with all threads and LWPs duplicated in the child.

     Note that if a program is  linked  with  both  libraries  (-
     lthread  and  -lpthread),  the POSIX semantic of fork() pre-
     vails.

With fork1() you're left with on thread; when linking w/ -lpthread,
there's no difference between fork() and fork1().

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

fork vs fork1 on 2.6 MT app

Post by Casper H.S. Dik - Network Security Engine » Fri, 16 Jul 1999 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>   I thought that I should give some more info on why I need this info.
>We have a MT app(pthreads). One of the threads does a fork1. The child
>process does a malloc before it does an exec. Sometimes the the call to
>fork1 does not return. So at this point we have two of our processes
>running. If I attach the child process through dbx and check I find that
>it is stuck in malloc. I have included below the relavent lines of the
>trace. The child is stuck when it is trying to acquire a lock.

Yes, that can happen easily.  If you call fork1() while another
thread holds the malloc_lock, and then call malloc, your application
will hang.

Quote:>   Going through the man pages of fork/fork1 and pthread_atfork I
>concluded that all the libraries that use locks need to call
>pthread_atfork in their .init section. These man pages say that this
>needs to be done to prevent any deadlocks in the child. I can probably
>assume that the library supplying malloc (libc ?) is doing this
>correctly.

The C library is not fork1() safe, I believe.  Consequencly, you can't
call malloc (and thus a whole bunch of other stuff) after fork1().

(All system calls and libthread calls are fork1() safe)

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

fork vs fork1 on 2.6 MT app

Post by Randy Reite » Sun, 18 Jul 1999 04:00:00


Wanted.

A streams/device driver consultant/guru.

Please contact via email.

Randy

 
 
 

1. fork vs fork1 on Solaris 2.6

 Hi,

   I want to know the difference between fork and fork1 in a MT app
using pthreads on Solaris 2.6.

   Here is why I need it. We have a MT app(pthreads). One of the threads
does a fork1. The child process does a malloc before it does an exec.
Sometimes the the call to fork1 does not return. So at this point we
have two of our processes running. If I attach the child process through
dbx and check I find that it is stuck in malloc. I have included below
the relavent lines of the trace. The child is stuck when it is trying to
acquire a lock.

   Going through the man pages of fork/fork1 and pthread_atfork I
concluded that all the libraries that use locks need to call
pthread_atfork in their .init section. These man pages say that this
needs to be done to prevent any deadlocks in the child. I can probably
assume that the library supplying malloc (libc ?) is doing this
correctly.

   Earlier our code would actually use fork and not fork1, but we faced
some other probs with this and found that using fork1 solved our
problem. Now we are having the above problem using fork1. From the man
page I do not find any difference between fork & fork1 in a MT app using
pthreads.

    So can anybody tell me the differences between the two calls in such
an app. I cannot post any code as its too big and I have not tried to
simulate the problem in a sample app.

regards
Ranga

  [1] _lwp_sema_wait(0xee305e80, 0x1, 0x0, 0x0, 0xff00, 0xff), at
0xee9396f0
  [2] _park(0xee305de0, 0xee305e80, 0x0, 0xee305e5c, 0xee305e58,
0xee305e54), at 0xef24776c
  [3] _mutex_adaptive_lock(0xee9a6600, 0x4c00, 0xef265250, 0x1, 0x4d58,
0xfffeffff), at 0xef2487b0
  [4] _mutex_lock(0xee9a6600, 0xef265250, 0x0, 0x0, 0x0, 0x0), at
0xef2484f8
  [5] malloc(0x15, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xee945a40

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

2. Mac G3/266 LinuxPPC setup weirdness...

3. interrupted sys call due to fork in MT app

4. A problem of Xstation 150

5. interrupted system call due to fork in a MT app

6. Sun to Linux tar problem

7. interrupted sys call due to fork in MT app

8. PCI Linux Driver Development Questions...

9. SunOS 5.6 vs Solaris 2.6 vs Solaris 7 vs Solaris 8

10. threads, fork/fork1 and activity before exec...

11. libqt3-mt vs. libqt3c102-mt on Debian

12. PGP 2.6.3i vs. 2.6.2s

13. market share of solaris versions (2.6 vs. 2.7 vs. 8)