diff --git a/sql/log.cc b/sql/log.cc index 6e11f4bbe5d..a938dcbc9f8 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -9597,9 +9597,7 @@ binlog_background_thread(void *arg __attribute__((unused))) THD_STAGE_INFO(thd, stage_binlog_stopping_background_thread); - mysql_mutex_lock(&LOCK_thread_count); delete thd; - mysql_mutex_unlock(&LOCK_thread_count); my_thread_end(); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index cb4f95212ef..404836b4312 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4630,6 +4630,7 @@ static int init_thread_environment() mysql_mutex_init(key_LOCK_global_system_variables, &LOCK_global_system_variables, MY_MUTEX_INIT_FAST); mysql_mutex_record_order(&LOCK_active_mi, &LOCK_global_system_variables); + mysql_mutex_record_order(&LOCK_status, &LOCK_thread_count); mysql_rwlock_init(key_rwlock_LOCK_system_variables_hash, &LOCK_system_variables_hash); mysql_mutex_init(key_LOCK_prepared_stmt_count, diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 697da6fa10e..f2437a6953b 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -1372,10 +1372,11 @@ handle_rpl_parallel_thread(void *arg) thd->reset_db(NULL, 0); thd_proc_info(thd, "Slave worker thread exiting"); thd->temporary_tables= 0; + mysql_mutex_lock(&LOCK_thread_count); - THD_CHECK_SENTRY(thd); - delete thd; + thd->unlink(); mysql_mutex_unlock(&LOCK_thread_count); + delete thd; mysql_mutex_lock(&rpt->LOCK_rpl_thread); rpt->running= false; diff --git a/sql/slave.cc b/sql/slave.cc index e9bcfb073b4..5410192a8dd 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -311,9 +311,7 @@ handle_slave_init(void *arg __attribute__((unused))) thd->get_stmt_da()->sql_errno(), thd->get_stmt_da()->message()); - mysql_mutex_lock(&LOCK_thread_count); delete thd; - mysql_mutex_unlock(&LOCK_thread_count); thread_safe_decrement32(&service_thread_count); signal_thd_deleted(); my_thread_end(); @@ -4961,8 +4959,9 @@ err_during_init: mysql_mutex_unlock(&LOCK_active_mi); mysql_mutex_lock(&LOCK_thread_count); - delete thd; + thd->unlink(); mysql_mutex_unlock(&LOCK_thread_count); + delete thd; thread_safe_decrement32(&service_thread_count); signal_thd_deleted();