[M3devel] fork/cvsup

Jay K jay.krell at cornell.edu
Wed Mar 17 08:47:45 CET 2010


http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/fork.2.html

 

 

There are limits to what you can do in the child process.  To be totally safe you should restrict your-self yourself
     self to only executing async-signal safe operations until such time as one of the exec functions is
     called.  All APIs, including global data symbols, in any framework or library should be assumed to be
     unsafe after a fork() unless explicitly documented to be safe or async-signal safe.  If you need to use
     these frameworks in the child process, you must exec.  In this situation it is reasonable to exec your-self. yourself.
     self.


 

http://www.opengroup.org/onlinepubs/000095399/functions/fork.html

 

Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. [THR]   Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls. 

 

 

I've run through a few theories so far.

Current thinking is related to what Tony said:

 use pthread_atfork: 

   in prepare, stopworld 

   in parent, resumeworld 

   You don't want the child to be mid-gc for example, on another thread. Or mid-anything.

   in child, reinitialize -- current thread is the only thread

 

 

Also in the cvsup code, ShutDown should just call DoShutDown immediately.

I did that, without m3core changes, and it hits an error in the pthread code, signaling a nonexistant thread.

pthread_atfork/child should address that -- child shouldn't retain a record of all the threads in the parent.

 

 

I don't have a theory as to why user threads work.

 

 

I experimented with malloc vs. static alloc vs. sbrk vs. mmap(private) vs. mmap(shared).

I was expecting more cases to act like mmap(shared), but none did, only it.

 

 

I experimented with having mutexes and condition variables be initialize up front instead of on-demand.

Via changing cvsup to lock/unlock or broadcast immediately upon creating them.

On the theory that might let them work across process.

That didn't make a difference.

 

 

 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100317/172569e9/attachment-0001.html>


More information about the M3devel mailing list