[M3devel] Fwd: Re: Fwd: Fork bug

Rodney M. Bates rodney_bates at lcwb.coop
Tue Jul 8 21:20:28 CEST 2014


Resent after 24 hours:


While we are working on MUTEX, I would like to propose making them
what I believe is meant by a recursive mutex, that is, one thread
can lock multiple times, the mutex being released only when the number
of unlocks catches up with the number of locks.

I don't remember the details off the top of my head, but there is a
place in Trestle where you have to acquire a MUTEX but it is very
difficult or impossible to know whether different code on the same
thread already has done so.  The different code isn't under your
control either.  Some runtime scheme to figure it out dynamically
would be tantamount to, but messier than, just having a recursive MUTEX.

I recall there are other places as well where similar problems arise.
It would greatly simplify things when needed.

The only disadvantage I can think of is there might be a case where
runtime detection of a second lock attempt by the same thread would
help find a bug.  Maybe the RTS could have a way of setting the
behavior of a specific MUTEX.

On 07/03/2014 02:28 PM, Tony Hosking wrote:
> 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 <mailto: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 <mailto: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
>

-- 
Rodney Bates
rodney.m.bates at acm.org





More information about the M3devel mailing list