Delay background_thread_ctl_init to right before thread creation.
ctl_init sets isthreaded, which means it should be done without holding any locks.
This commit is contained in:
parent
79e83451ff
commit
a2e6eb2c22
@ -848,9 +848,6 @@ background_thread_boot1(tsdn_t *tsdn) {
|
|||||||
malloc_mutex_rank_exclusive)) {
|
malloc_mutex_rank_exclusive)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (opt_background_thread) {
|
|
||||||
background_thread_ctl_init(tsdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
background_thread_info = (background_thread_info_t *)base_alloc(tsdn,
|
background_thread_info = (background_thread_info_t *)base_alloc(tsdn,
|
||||||
b0get(), ncpus * sizeof(background_thread_info_t), CACHELINE);
|
b0get(), ncpus * sizeof(background_thread_info_t), CACHELINE);
|
||||||
|
@ -1522,6 +1522,8 @@ malloc_init_hard(void) {
|
|||||||
post_reentrancy(tsd);
|
post_reentrancy(tsd);
|
||||||
malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock);
|
malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock);
|
||||||
|
|
||||||
|
witness_assert_lockless(witness_tsd_tsdn(
|
||||||
|
tsd_witness_tsdp_get_unsafe(tsd)));
|
||||||
malloc_tsd_boot1();
|
malloc_tsd_boot1();
|
||||||
/* Update TSD after tsd_boot1. */
|
/* Update TSD after tsd_boot1. */
|
||||||
tsd = tsd_fetch();
|
tsd = tsd_fetch();
|
||||||
@ -1529,8 +1531,11 @@ malloc_init_hard(void) {
|
|||||||
assert(have_background_thread);
|
assert(have_background_thread);
|
||||||
/*
|
/*
|
||||||
* Need to finish init & unlock first before creating background
|
* Need to finish init & unlock first before creating background
|
||||||
* threads (pthread_create depends on malloc).
|
* threads (pthread_create depends on malloc). ctl_init (which
|
||||||
|
* sets isthreaded) needs to be called without holding any lock.
|
||||||
*/
|
*/
|
||||||
|
background_thread_ctl_init(tsd_tsdn(tsd));
|
||||||
|
|
||||||
malloc_mutex_lock(tsd_tsdn(tsd), &background_thread_lock);
|
malloc_mutex_lock(tsd_tsdn(tsd), &background_thread_lock);
|
||||||
bool err = background_thread_create(tsd, 0);
|
bool err = background_thread_create(tsd, 0);
|
||||||
malloc_mutex_unlock(tsd_tsdn(tsd), &background_thread_lock);
|
malloc_mutex_unlock(tsd_tsdn(tsd), &background_thread_lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user