Question about pthread_getspecific with jemalloc

Jason Evans jasone at canonware.com
Thu Nov 3 19:37:58 PDT 2011


On 06/14/2011 02:13 PM, Ethan Burns wrote:
> On Tue, Jun 14, 2011 at 1:48 PM, Ethan Burns<burns.ethan at gmail.com>  wrote:
>> I am experiencing strange behavior with pthread_getspecific when I
>> link with jemalloc.  What happens is, after calling malloc(), the
>> value of one of my keys seems to change out from under me.  Here is a
>> small example that demonstrates this:
>> http://itsapad.appspot.com/fancy/6.  I am using jemalloc-2.2.1 on
>> Linux.  If I compile the example with gcc (ver 4.4.3) using the
>> following command: 'gcc -lpthread main.c' then both calls to
>> pthread_getspecific return a NULL pointer as expected.  When I link
>> with jemalloc, however, ('gcc -ljemalloc -lpthread main.c') then the
>> second call to pthread_getspecific returns some non-NULL value.  Is
>> this a known bug or am I doing something wrong?
>
> I have done a bit of digging.  It looks like the call to the macro
> ARENA_SET on src/jemalloc.c:794 calls pthread_setspecific on the
> arenas_tsd key before the key is actually created on
> src/jemalloc.c:800.  The attached patch seems to fix the problem.  I
> am not familiar with the code so I am not really sure that this patch
> doesn't introduce a new bug but if so, I didn't hit it.
>
> Ethan

Thanks for the report (from you and others).  Apologies for letting this 
sit for so long.  This is fixed in the dev branch now, and I plan to 
release 2.2.4 this week.

Jason



More information about the jemalloc-discuss mailing list