Re: [PATCH 1/2] Make xmalloc and xrealloc thread-safe
- From
Fredrik Kuivinen <frekui@gmail.com>
- Date
- Mar 23, 2010, 21:21 UTC
- Message-ID
- <4c8ef71003231421u789c4332h461c066add0ec7b1@mail.gmail.com>
- In-Reply-To
- <20100323184309.GA31668@spearce.org>
On Tue, Mar 23, 2010 at 19:43, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 22 quoted lines
> Fredrik Kuivinen <frekui@gmail.com> wrote:
>> +static int multiple_threads;
>> +#ifndef NO_PTHREADS
>> +int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
>> + void *(*start_routine)(void*), void *arg)
>> +{
>> + multiple_threads = 1;
>> + return pthread_create(thread, attr, start_routine, arg);
>> +}
>> +#endif
>> +
>> void *xmalloc(size_t size)
>> {
>> void *ret = malloc(size);
>> if (!ret && !size)
>> ret = malloc(1);
>> - if (!ret) {
>> + if (!ret && !multiple_threads) {
>> release_pack_memory(size, -1);
>
> So by "make thread safe" you really mean "disable release of
> least-frequently used pack windows once any thread starts".Yes.
> If that is what we are doing, disabling the release of pack windows > when malloc fails, why can't we do that all of the time?
The idea was that most git programs are single threaded, so they can still benefit from releasing the pack windows when they are low on memory.
- Fredrik