<html><head><base href="x-msg://3/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Can you sketch the approach you've taken?<div><br>
<br><div><div>On 17 Mar 2010, at 11:39, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">I have something working on Solaris now.<br>More details after testing on Linux and Darwin.<br> <br> - Jay<br> <br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Wed, 17 Mar 2010 14:01:15 +0000<br>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: Re: [M3devel] fork/cvsup<br><br>Exec what?<br>You'd have to change the code to carefully reach the same place.<br> <br> - Jay<br> <br><hr id="ecxstopSpelling">Subject: Re: [M3devel] fork/cvsup<br>From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Wed, 17 Mar 2010 09:28:14 -0400<br>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br><br><div><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><div style="word-wrap: break-word; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; letter-spacing: normal; color: rgb(0, 0, 0); word-spacing: 0px; "><div><span class="ecxecxApple-style-span" style="font-size: medium; "><font class="ecxecxApple-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="ecxecxApple-interchange-newline"><blockquote><span class="ecxecxApple-style-span" style="text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal medium/normal Helvetica; white-space: normal; letter-spacing: normal; word-spacing: 0px; "><div class="ecxecxhmmessage" style="font-family: Verdana; font-size: 10pt; "><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="ecxecxwhiteout" 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="ecxecxApple-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="ecxecxwhiteout" 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="ecxecxApple-converted-space"> </span>functions is called.<span class="ecxecxApple-converted-space"> </span><sup>[<a>THR</a>]</sup><span class="ecxecxApple-converted-space"> </span><img border="0" alt="[Option Start]" src="http://www.opengroup.org/onlinepubs/000095399/images/opt-start.gif"><span class="ecxecxApple-converted-space"> </span> Fork handlers may be established by means of the<span class="ecxecxApple-converted-space"> </span><a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_atfork.html"><i>pthread_atfork</i>()</a><span class="ecxecxApple-converted-space"> </span>function in order to maintain application invariants across<span class="ecxecxApple-converted-space"> </span><i>fork</i>() calls.<span class="ecxecxApple-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="ecxecxApple-converted-space"> </span><br>   in prepare, stopworld<span class="ecxecxApple-converted-space"> </span><br>   in parent, resumeworld<span class="ecxecxApple-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></div></span><br class="Apple-interchange-newline"></blockquote></div><br></div></body></html>