[PATCH] malloc-standard: synchronize on fork

Timo Teräs timo.teras at iki.fi
Tue Mar 29 03:47:55 UTC 2011


On 03/29/2011 01:06 AM, Rich Felker wrote:
> On Mon, Mar 28, 2011 at 11:43:00PM +0300, Timo Teräs wrote:
>>>> It is recursive mutex. It's works perfectly fine if same thread locks
>>>> that mutex multiple times.
>>>
>>> But not from a signal handler. There's almost surely a race between
>>> locking the mutex and having it in the right state so that the signal
>>> handler sees it's the owner.
>>
>> Oh. That's right. There's a race for that. I've been trying to figure
>> how glibc handles that, but it'd seem that it does not. Hmmh.
>>
>> Not sure what to do here. Need to think about it. Any great ideas?
> 
> You could enhance the recursive mutex implementation to be reentrant -
> having a single atomic int that serves as both the lock status and the
> owner and updating it with an atomic compare-and-swap should be one
> way to do this.

Yes, I got the same idea too. Looking at the code, it might be easier to
do a specific lock implementation for this. It'd be nice, if we had a
general purpose re-entrant mutex implementation, though.

- Timo


More information about the uClibc mailing list