diff options
| author | Qi Wang <interwq@gwu.edu> | 2017-06-01 00:04:56 -0700 |
|---|---|---|
| committer | Jason Evans <jasone@canonware.com> | 2017-06-01 09:00:07 -0700 |
| commit | c84ec3e9da66162943ee33afe73c7f898fa134e2 (patch) | |
| tree | eedd8a3dd585f95108c848f64493b931648a77a5 | |
| parent | fd0fa003e188e94beab8871ff0c17ea4a8a2c706 (diff) | |
| download | platform_external_jemalloc_new-c84ec3e9da66162943ee33afe73c7f898fa134e2.tar.gz platform_external_jemalloc_new-c84ec3e9da66162943ee33afe73c7f898fa134e2.tar.bz2 platform_external_jemalloc_new-c84ec3e9da66162943ee33afe73c7f898fa134e2.zip | |
Fix background thread creation.
The state initialization should be done before pthread_create.
| -rw-r--r-- | src/background_thread.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/background_thread.c b/src/background_thread.c index 800526f5..a89cad2e 100644 --- a/src/background_thread.c +++ b/src/background_thread.c @@ -317,34 +317,38 @@ background_thread_create(tsd_t *tsd, unsigned arena_ind) { bool need_new_thread; malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx); need_new_thread = background_thread_enabled() && !info->started; + if (need_new_thread) { + info->started = true; + background_thread_info_reinit(tsd_tsdn(tsd), info); + n_background_threads++; + } malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx); if (!need_new_thread) { return false; } pre_reentrancy(tsd); - int err; /* * To avoid complications (besides reentrancy), create internal * background threads with the underlying pthread_create. */ - if ((err = pthread_create_wrapper(&info->thread, NULL, - background_thread_entry, (void *)thread_ind)) != 0) { + int err = pthread_create_wrapper(&info->thread, NULL, + background_thread_entry, (void *)thread_ind); + post_reentrancy(tsd); + + if (err != 0) { malloc_printf("<jemalloc>: arena %u background thread creation " "failed (%d).\n", arena_ind, err); - } - post_reentrancy(tsd); + malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx); + info->started = false; + n_background_threads--; + malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx); - malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx); - assert(info->started == false); - if (err == 0) { - info->started = true; - background_thread_info_reinit(tsd_tsdn(tsd), info); - n_background_threads++; + return true; } - malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx); + assert(info->started); - return (err != 0); + return false; } bool |
