Drop high rank locks when creating threads.

Avoid holding arenas_lock and background_thread_lock when creating background
threads, because pthread_create may take internal locks, and potentially cause
deadlock with jemalloc internal locks.
This commit is contained in:
Qi Wang 2017-06-07 15:49:09 -07:00 committed by Qi Wang
parent 00869e39a3
commit 73713fbb27
5 changed files with 43 additions and 13 deletions

View file

@ -352,12 +352,15 @@ background_thread_create(tsd_t *tsd, unsigned arena_ind) {
}
pre_reentrancy(tsd);
malloc_mutex_unlock(tsd_tsdn(tsd), &background_thread_lock);
/*
* To avoid complications (besides reentrancy), create internal
* background threads with the underlying pthread_create.
* background threads with the underlying pthread_create, and drop
* background_thread_lock (pthread_create may take internal locks).
*/
int err = pthread_create_wrapper(&info->thread, NULL,
background_thread_entry, (void *)thread_ind);
malloc_mutex_lock(tsd_tsdn(tsd), &background_thread_lock);
post_reentrancy(tsd);
if (err != 0) {