Re: [PATCH] Make xmalloc and xrealloc thread-safe
- From
Fredrik Kuivinen <frekui@gmail.com>
- Date
- Mar 31, 2010, 06:57 UTC
- Message-ID
- <s2t4c8ef71003302357x5e9defa1l4dbde6391d533ca5@mail.gmail.com>
- In-Reply-To
- <alpine.LFD.2.00.1003271035360.694@xanadu.home>
On Sat, Mar 27, 2010 at 19:59, Nicolas Pitre <nico@fluxnic.net> wrote:
Show 16 quoted lines
> On Sat, 27 Mar 2010, Fredrik Kuivinen wrote:
>
>> On Wed, Mar 24, 2010 at 21:22, Nicolas Pitre <nico@fluxnic.net> wrote:
>> > +static void try_to_free_from_threads(size_t size)
>> > +{
>> > + read_lock();
>> > + release_pack_memory(size, -1);
>> > + read_unlock();
>> > +}
>> > +
>>
>> Will this really work in all cases? In the find_deltas -> try_delta ->
>> read_sha1_file -> ... -> xmalloc call path, the mutex is already
>> locked when we get to xmalloc.
>
> You're right. Damn.A simple fix is to make it a recursive mutex instead. This will work with a minimal change in win32 as well as the CRITICAL_SECTION type is recursive.
I guess the downside is that the locking potentially gets slightly slower.
- Fredrik