[PATCH 2/2] Add support for LinuxThreads.

Jason Evans jasone at canonware.com
Tue Oct 22 13:16:55 PDT 2013


On Oct 21, 2013, at 2:12 PM, Leonard Crestez <lcrestez at ixiacom.com> wrote:
> When using LinuxThreads pthread_setspecific triggers recursive allocation on all threads. Work around this by creating a global linked list of in-progress tsd initializations.
> 
> This modifies the _tsd_get_wrapper macro-generated function. When it has
> to initialize an TSD object it will push the item to the linked list
> first. If this causes a recursive allocation then the _get_wrapper
> request is satisfied from the list. When pthread_setspecific returns the item is removed from the list.
> 
> This effectively adds a very poor substitute for real TLS used only
> during pthread_setspecific allocation recursion.
> 
> Signed-off-by: Crestez Dan Leonard <lcrestez at ixiacom.com>
> ---
>  include/jemalloc/internal/tsd.h | 63 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 63 insertions(+)

I don't see how this code can work.  It stack-allocates block (struct tsd_init_block block;), then permanently links it into a ring.  There are other less critical issues (e.g. no cleanup during thread exit, using pthread_mutex_t rather than malloc_mutex_t, and coding style conformance), but let's worry first about whether there's a feasible way to restructure the initialization code.

Thanks,
Jason


More information about the jemalloc-discuss mailing list