<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Exec what?<BR>
You'd have to change the code to carefully reach the same place.<BR>
<BR>
- Jay<BR> <BR>
<HR id=stopSpelling>
Subject: Re: [M3devel] fork/cvsup<BR>From: hosking@cs.purdue.edu<BR>Date: Wed, 17 Mar 2010 09:28:14 -0400<BR>CC: m3devel@elegosoft.com<BR>To: jay.krell@cornell.edu<BR><BR><BASE>
<DIV><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="WORD-WRAP: break-word"><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV><SPAN style="FONT-SIZE: medium" class=ecxApple-style-span><FONT class=ecxApple-style-span color=#0000ff face="'Gill Sans'">Why not just exec in the child?</FONT></SPAN></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></SPAN></DIV><BR>
<DIV>
<DIV>On 17 Mar 2010, at 03:47, Jay K wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxhmmessage><A href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/fork.2.html">http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/fork.2.html</A><BR> <BR><FONT face=""></FONT> <BR><FONT face="">There are limits to what you can do in the child process. To be totally safe you should restrict your-<FONT class=ecxwhiteout color=#ffffff size=1>self yourself</FONT><BR> self to only executing async-signal safe operations until such time as one of the exec functions is<BR> called. All APIs, including global data symbols, in any framework or library should be assumed to be<BR> unsafe after a<SPAN class=ecxApple-converted-space> </SPAN><B>fork</B>() unless explicitly documented to be safe or async-signal safe. If you need to use<BR> these frameworks in the child process, you must exec. In this situation it is reasonable to exec your-<FONT class=ecxwhiteout color=#ffffff size=1>self. yourself.</FONT><BR> self.<BR><BR></FONT><FONT face=""></FONT> <BR><FONT face=""><A href="http://www.opengroup.org/onlinepubs/000095399/functions/fork.html">http://www.opengroup.org/onlinepubs/000095399/functions/fork.html</A></FONT><BR><FONT face=""></FONT> <BR><FONT face="">Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the<I><A href="http://www.opengroup.org/onlinepubs/000095399/functions/exec.html">exec</A></I><SPAN class=ecxApple-converted-space> </SPAN>functions is called.<SPAN class=ecxApple-converted-space> </SPAN><SUP>[<A>THR</A>]</SUP><SPAN class=ecxApple-converted-space> </SPAN><IMG border=0 alt="[Option Start]" src="http://www.opengroup.org/onlinepubs/000095399/images/opt-start.gif"><SPAN class=ecxApple-converted-space> </SPAN> Fork handlers may be established by means of the<SPAN class=ecxApple-converted-space> </SPAN><A href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_atfork.html"><I>pthread_atfork</I>()</A><SPAN class=ecxApple-converted-space> </SPAN>function in order to maintain application invariants across<SPAN class=ecxApple-converted-space> </SPAN><I>fork</I>() calls.<SPAN class=ecxApple-converted-space> </SPAN><IMG border=0 alt="[Option End]" src="http://www.opengroup.org/onlinepubs/000095399/images/opt-end.gif"><BR> <BR> <BR>I've run through a few theories so far.<BR>Current thinking is related to what Tony said:<BR> use pthread_atfork:<SPAN class=ecxApple-converted-space> </SPAN><BR> in prepare, stopworld<SPAN class=ecxApple-converted-space> </SPAN><BR> in parent, resumeworld<SPAN class=ecxApple-converted-space> </SPAN><BR> You don't want the child to be mid-gc for example, on another thread. Or mid-anything.<BR> in child, reinitialize -- current thread is the only thread<BR> <BR> <BR>Also in the cvsup code, ShutDown should just call DoShutDown immediately.<BR>I did that, without m3core changes, and it hits an error in the pthread code, signaling a nonexistant thread.<BR>pthread_atfork/child should address that -- child shouldn't retain a record of all the threads in the parent.<BR> <BR> <BR>I don't have a theory as to why user threads work.<BR> <BR> <BR>I experimented with malloc vs. static alloc vs. sbrk vs. mmap(private) vs. mmap(shared).<BR>I was expecting more cases to act like mmap(shared), but none did, only it.<BR> <BR> <BR>I experimented with having mutexes and condition variables be initialize up front instead of on-demand.<BR>Via changing cvsup to lock/unlock or broadcast immediately upon creating them.<BR>On the theory that might let them work across process.<BR>That didn't make a difference.<BR> <BR> <BR> - Jay<BR></FONT></DIV></SPAN></BLOCKQUOTE></DIV><BR> </body>
</html>