<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Or, more directly, why do we not simply use vfork for Process.Create as we used to? It suspends the parent until the exec, which avoids all the nastiness, so long as we are careful in the child until the exec.<div><br></div><div>As I recall though, cvsup relied on full-blown fork, which was how we ended up in this mess in the first place.</div><div><br></div><div>So, that means a fix is still needed.</div><div><br></div><div><div>I suspect we will need to revise the implementation of MUTEX to avoid having the pthread mutex held while the Modula-3 MUTEX is held. Instead, we’d need state in MUTEX to record the holder, plus a waiters field to record those waiting for the mutex. Then, we can guarantee that no pthread mutex will be locked at the time of the fork using the machinery we already have.</div><div><br></div><div><div><div>On Jul 3, 2014, at 3:28 PM, Tony Hosking <<a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I wonder if we should not move to a surrogate parent model to make this cleaner in general?</div><div>Since fork is (or should be) only used in service of creating a new process (i.e., fork + exec) then this technique would save us a lot of grief.</div><div>Thoughts?</div><div><br></div><table border="0" cellspacing="0" cellpadding="0" width="100%" style="font-family: Times; position: static; z-index: auto;"><tbody><tr><td width="93%" valign="TOP" align="left"><font size="2" face="Arial" color="010100">In the surrogate parent model, a program forks a child process at initialization time. The sole purpose of the child is to serve as a sort of "surrogate parent" for the original process should it ever need to fork another child. After initialization, the original parent can proceed to create its additional threads. When it wants to </font><font size="2" face="Arial" color="010100"><i>exec</i></font><font size="2" face="Arial" color="010100"> an image, it communicates this to its child (which has remained single-threaded). The child then performs the </font><font size="2" face="Arial" color="010100"><i>fork</i></font><font size="2" face="Arial" color="010100"> and </font><font size="2" face="Arial" color="010100"><i>exec</i></font><font size="2" face="Arial" color="010100"> on behalf of the original process. </font></td></tr></tbody></table><div><br></div>
<div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family: Helvetica;"><b>From: </b></span><span style="font-family:'Helvetica';">Peter McKinna <<a href="mailto:peter.mckinna@gmail.com">peter.mckinna@gmail.com</a>><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family: Helvetica;"><b>Subject: </b></span><span style="font-family:'Helvetica';"><b>Fork bug</b><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family: Helvetica;"><b>Date: </b></span><span style="font-family:'Helvetica';">July 2, 2014 at 10:30:24 PM EDT<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family: Helvetica;"><b>To: </b></span><span style="font-family:'Helvetica';">Antony Hosking <<a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a>><br></span></div><br><div><div dir="ltr">Hi Tony,<div><br><div> That fork bug on posix doesn't appear to be fixed, so just to recap the problem. In the threadtest program if you have a bunch of threads creating mutexes and having them collected then get a thread that does a few forks what can happen is that the child executes atforkchild as I think the first thing it does which calls initwithstackbase which does an allocation and possible collection. Unfortunately the weaktable from the parent may be non empty and this is the only thread executing. It calls the cleanup of those mutexes of nonexistant threads some of which may be locked. If they are locked then pthread_mutex_destroy returns ebusy. Then the child exits with the abort in pthread_mutex_delete.</div>
<div> Whether the abort is needed I dont know. In this case the error can be safely ignored. One could try to see if the owner of the mutex is still alive and not abort in that case. Otherwise if one is sure the child is going to do an exec almost immediately then disabling the collector in atforkchild could work.</div>
</div><div> In the broader picture anything thats got a weak ref still active could cause problems if one thread does a fork. The weak callback could do anything.</div><div> Anyway I dont know what the fix is.</div><div>
<br></div><div>Peter</div></div>
</div></blockquote></div><br></div></blockquote></div><br></div></div></body></html>