mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-27 13:22:14 +03:00
Fix background thread initialization race
This commit is contained in:
parent
d4908fe44a
commit
4d0ffa075b
3 changed files with 190 additions and 2 deletions
|
|
@ -547,8 +547,13 @@ background_thread_create_locked(tsd_t *tsd, unsigned arena_ind) {
|
|||
|
||||
bool need_new_thread;
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
||||
/*
|
||||
* The last check is there to leave Thread 0 creation entirely
|
||||
* to the initializing thread (arena 0).
|
||||
*/
|
||||
need_new_thread = background_thread_enabled()
|
||||
&& (info->state == background_thread_stopped);
|
||||
&& (info->state == background_thread_stopped)
|
||||
&& (thread_ind != 0 || arena_ind == 0);
|
||||
if (need_new_thread) {
|
||||
background_thread_init(tsd, info);
|
||||
}
|
||||
|
|
@ -560,7 +565,6 @@ background_thread_create_locked(tsd_t *tsd, unsigned arena_ind) {
|
|||
/* Threads are created asynchronously by Thread 0. */
|
||||
background_thread_info_t *t0 = &background_thread_info[0];
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), &t0->mtx);
|
||||
assert(t0->state == background_thread_started);
|
||||
pthread_cond_signal(&t0->cond);
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &t0->mtx);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue