[M3devel] Fwd: Re: Fwd: Fork bug

Coleburn, Randy rcolebur at SCIRES.COM
Sat Aug 2 03:08:34 CEST 2014


Sorry for the delay in responding, but I've been out on travel.

In Trestle the authors devised the concept of Locking Levels and used LL pragmas in the code so that proper ordering could be verified.

Actually, the problem comes up in other multi-threaded situations and the coder has to take all this into consideration to prevent getting into a deadlock or starvation situation.  I've used partial ordering techniques similar to what was done in Trestle to solve this problem.

I do NOT favor the proposed change in MUTEX.

In addition to locking levels/orders, there are different abstractions that sometimes should be used instead of MUTEX.  I have written several such abstractions.

For example, ConcurrencyControl.i3:
Provide for a mechanism to achieve concurrency control.  The abstraction
provided is one of readers and writers, where at any instance of time there
can be either zero or more readers, or zero or one writer, that is at time t
one and only one of the following 3 conditions applies:
   1.  (numReaders = 0) AND (numWriters = 0).
   2.  (numReaders > 0) AND (numWriters = 0).
   3.  (numReaders = 0) AND (numWriters = 1).

For example, GateKeeper.i3:
Provide an abstraction for controlling concurrency.  The abstraction is that
of a gatekeeper who can lock/unlock the gate and who regulates entry/exit 
via the gate, thereby controlling the number of occupants.

I can probably arrange to share some of this code if desired.

--Randy Coleburn

-----Original Message-----
From: Rodney M. Bates [mailto:rodney_bates at lcwb.coop] 
Sent: Tuesday, July 08, 2014 3:20 PM
To: m3devel
Subject: EXT:[M3devel] Fwd: Re: Fwd: Fork bug


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