[M3devel] Fwd: Fork bug

Tony Hosking hosking at cs.purdue.edu
Thu Jul 3 21:28:30 CEST 2014


I wonder if we should not move to a surrogate parent model to make this cleaner in general?
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.
Thoughts?

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 exec an image, it communicates this to its child (which has remained single-threaded). The child then performs the fork and exec on behalf of the original process. 


Begin forwarded message:

> From: Peter McKinna <peter.mckinna at gmail.com>
> Subject: Fork bug
> Date: July 2, 2014 at 10:30:24 PM EDT
> To: Antony Hosking <hosking at cs.purdue.edu>
> 
> Hi Tony,
> 
>   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.
>   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.
>   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.
>   Anyway I dont know what the fix is.
> 
> Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20140703/fe82079c/attachment-0001.html>


More information about the M3devel mailing list