From: Shawn O. Pearce Date: Tue, 23 Mar 2010 18:43:09 GMT Subject: Re: [PATCH 1/2] Make xmalloc and xrealloc thread-safe Message-ID: <20100323184309.GA31668@spearce.org> In-Reply-To: <20100323173114.GB4218@fredrik-laptop> Fredrik Kuivinen 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". 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? -- Shawn.