Use real pthread_create for creating background threads.

This commit is contained in:
Qi Wang 2017-05-30 20:45:29 -07:00 committed by Qi Wang
parent 9a86c9bd30
commit 508f54b02b
2 changed files with 9 additions and 3 deletions

View File

@ -364,7 +364,11 @@ background_thread_create(tsd_t *tsd, unsigned arena_ind) {
pre_reentrancy(tsd); pre_reentrancy(tsd);
int err; int err;
load_pthread_create_fptr(); load_pthread_create_fptr();
if ((err = pthread_create(&info->thread, NULL, /*
* To avoid complications (besides reentrancy), create internal
* background threads with the underlying pthread_create.
*/
if ((err = pthread_create_fptr(&info->thread, NULL,
background_thread_entry, (void *)thread_ind)) != 0) { background_thread_entry, (void *)thread_ind)) != 0) {
malloc_printf("<jemalloc>: arena %u background thread creation " malloc_printf("<jemalloc>: arena %u background thread creation "
"failed (%d).\n", arena_ind, err); "failed (%d).\n", arena_ind, err);
@ -645,7 +649,9 @@ load_pthread_create_fptr(void) {
if (pthread_create_fptr) { if (pthread_create_fptr) {
return pthread_create_fptr; return pthread_create_fptr;
} }
#ifdef JEMALLOC_LAZY_LOCK
isthreaded = true;
#endif
pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create"); pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create");
if (pthread_create_fptr == NULL) { if (pthread_create_fptr == NULL) {
malloc_write("<jemalloc>: Error in dlsym(RTLD_NEXT, " malloc_write("<jemalloc>: Error in dlsym(RTLD_NEXT, "

View File

@ -30,7 +30,7 @@ static malloc_mutex_t *postponed_mutexes = NULL;
static void static void
pthread_create_once(void) { pthread_create_once(void) {
pthread_create_fptr = load_pthread_create_fptr(); pthread_create_fptr = load_pthread_create_fptr();
isthreaded = true; assert(isthreaded);
} }
JEMALLOC_EXPORT int JEMALLOC_EXPORT int