[M3devel] pthread_atfork

Jay K jay.krell at cornell.edu
Sat Feb 12 11:24:01 CET 2011


I wrote that.

As I recall, FreeBSD < 6 doesn't have pthread_atfork.

I think that was based on reading the man pages.

So, yes. What would you suggest?





All this atfork stuff came about as part of getting cvsupd to work.

  With pthreads/kernel threads. It historically worked, with Modula-3 user threads.

  Modula-3 user threads have this funny property that all threads survive work.

  With pthreads/kernel threads, fork gives you a new process with just one thread.

   (Solaris has fork1 and forkall, and fork maybe used to be forkall, but now it is fork1).





cvsupd is one of those slightly unusual programs that does "fork and then do more work"

as supposed to the more typical "fork and exec".



Which is to say..I don't know. Maybe, don't expect pthreads to work on FreeBSD < 6?

At least not in a process that ever calls fork? Or does "fork and then more work"?





In reality, i think a lot of libraries have trouble with "fork and then do more work", but

I don't know. I recall vague notices in the Apple/Darwin manpages not to assume

this works -- the obvious implication that there is plenty of use of pthreads e.g. mutexes,

but relatively little use of pthread_atfork.





You could perhaps replace all uses of fork with a function that called the fork handlers,

then fork, then the other handlers. That is probably what I meant in the comment

about this being easy to fix.

You might though then run into the problem that callers of fork can't do much

before exec...oh, that's vfork I bet actually.





 - Jay






> To: hosking at cs.purdue.edu
> Date: Fri, 11 Feb 2011 19:05:25 -0800
> From: mika at async.caltech.edu
> CC: m3devel at elegosoft.com; jay.krell at cornell.edu
> Subject: [M3devel] pthread_atfork
> 
> Tony,
> 
> What's RTProcessC.c doing?
> 
> I note the following cryptic comment:
> 
> /* NOTE: Even userthreads now depends
>  * on availability of pthreads.
>  * This can be fixed if need be.
>  */
> 
> now further down we can read:
> 
> #if defined(_WIN32) \
>         || defined(__vms) \
>         || (defined(__FreeBSD__) && (__FreeBSD__ < 6))
>     return 0;
> #else
>     while (1)
>     {
>       int i = pthread_atfork(prepare, parent, child);
>       if (i != EAGAIN)
>         return i;
>       sleep(0);
>     }
> #endif
> 
> so on FreeBSD 5 (what I'm running on my "FreeBSD4" system),
> RTProcess.RegisterForkHandlers does nothing?
> 
> Hmmm.....
> 
>     Mika
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20110212/0124a482/attachment-0002.html>


More information about the M3devel mailing list