From bf7cfa2535618bfe9962c725555680e799fdcd18 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 5 Dec 2024 15:31:40 +1100 Subject: [PATCH] MDEV-35574 remove obsolete pthread_exit calls Threads can normally exit without a explicit pthread_exit call. There seem to date to old glibc bugs, many around 2.2.5. The semi related bug was https://bugs.mysql.com/bug.php?id=82886. To improve safety in the signal handlers DBUG_* code was removed. These where also needed to avoid some MSAN unresolved stack issues. This is effectively a backport of 2719cc4925c032f483edb0e61c0f487e0c429ae6. --- client/mysqlimport.c | 1 - client/mysqltest.cc | 1 - mysys/thr_alarm.c | 3 +-- mysys/thr_timer.c | 3 +-- plugin/feedback/sender_thread.cc | 1 - sql/mysqld.cc | 7 +------ storage/mroonga/vendor/groonga/src/groonga_benchmark.c | 7 +------ tests/thread_test.c | 1 - unittest/mysys/stack_allocation-t.c | 1 - unittest/sql/my_apc-t.cc | 1 - 10 files changed, 4 insertions(+), 22 deletions(-) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 405eda8cc10..687fd8c2061 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -631,7 +631,6 @@ error: pthread_cond_signal(&count_threshhold); pthread_mutex_unlock(&counter_mutex); mysql_thread_end(); - pthread_exit(0); return 0; } diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 71025814fcf..becb411947f 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -991,7 +991,6 @@ end_thread: cn->mysql= 0; cn->query_done= 1; mysql_thread_end(); - pthread_exit(0); DBUG_RETURN(0); } diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index af22e7cc45c..6a3bc153462 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -566,8 +566,7 @@ static void *alarm_handler(void *arg __attribute__((unused))) alarm_thread_running= 0; mysql_cond_signal(&COND_alarm); mysql_mutex_unlock(&LOCK_alarm); - pthread_exit(0); - return 0; /* Impossible */ + return 0; } #endif /* USE_ALARM_THREAD */ #endif diff --git a/mysys/thr_timer.c b/mysys/thr_timer.c index 00fc74cdf77..6e9e5a421e0 100644 --- a/mysys/thr_timer.c +++ b/mysys/thr_timer.c @@ -330,8 +330,7 @@ static void *timer_handler(void *arg __attribute__((unused))) } mysql_mutex_unlock(&LOCK_timer); my_thread_end(); - pthread_exit(0); - return 0; /* Impossible */ + return 0; } diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 68aaa4c5dc7..453f367c289 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -290,7 +290,6 @@ pthread_handler_t background_thread(void *arg __attribute__((unused))) } my_thread_end(); - pthread_exit(0); return 0; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index dd2d9df4c1c..a9fa24c2064 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2948,7 +2948,6 @@ pthread_handler_t signal_hand(void *) sigset_t set; int sig; my_thread_init(); // Init new thread - DBUG_ENTER("signal_hand"); signal_thread_in_use= 1; /* @@ -3014,7 +3013,6 @@ pthread_handler_t signal_hand(void *) /* switch to the old log message processing */ logger.set_handlers(global_system_variables.sql_log_slow ? LOG_FILE:LOG_NONE, opt_log ? LOG_FILE:LOG_NONE); - DBUG_PRINT("info",("Got signal: %d abort_loop: %d",sig,abort_loop)); break_connect_loop(); DBUG_ASSERT(abort_loop); @@ -3050,12 +3048,9 @@ pthread_handler_t signal_hand(void *) break; /* purecov: tested */ } } - DBUG_PRINT("quit", ("signal_handler: calling my_thread_end()")); my_thread_end(); - DBUG_LEAVE; // Must match DBUG_ENTER() signal_thread_in_use= 0; - pthread_exit(0); // Safety - return(0); /* purecov: deadcode */ + return nullptr; } static void check_data_home(const char *path) diff --git a/storage/mroonga/vendor/groonga/src/groonga_benchmark.c b/storage/mroonga/vendor/groonga/src/groonga_benchmark.c index 267bb278764..a4918137d4f 100644 --- a/storage/mroonga/vendor/groonga/src/groonga_benchmark.c +++ b/storage/mroonga/vendor/groonga/src/groonga_benchmark.c @@ -271,12 +271,7 @@ error_exit_in_thread(intptr_t code) CRITICAL_SECTION_ENTER(grntest_cs); grntest_stop_flag = 1; CRITICAL_SECTION_LEAVE(grntest_cs); -#ifdef WIN32 - _endthreadex(code); -#else - pthread_exit((void *)code); -#endif /* WIN32 */ - return 0; + return code; } diff --git a/tests/thread_test.c b/tests/thread_test.c index d0c33b47b9c..a26e69bdf75 100644 --- a/tests/thread_test.c +++ b/tests/thread_test.c @@ -70,7 +70,6 @@ end: thread_count--; pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_mutex_unlock(&LOCK_thread_count); - pthread_exit(0); return 0; } diff --git a/unittest/mysys/stack_allocation-t.c b/unittest/mysys/stack_allocation-t.c index 2b044c80f42..23b75a8f148 100644 --- a/unittest/mysys/stack_allocation-t.c +++ b/unittest/mysys/stack_allocation-t.c @@ -91,7 +91,6 @@ pthread_handler_t thread_stack_check(void *arg __attribute__((unused))) test_stack_detection(1, STACK_ALLOC_SMALL_BLOCK_SIZE-1); test_stack_detection(2, STACK_ALLOC_SMALL_BLOCK_SIZE+1); my_thread_end(); - pthread_exit(0); return 0; } diff --git a/unittest/sql/my_apc-t.cc b/unittest/sql/my_apc-t.cc index 8fb9181377a..c91a5015b6e 100644 --- a/unittest/sql/my_apc-t.cc +++ b/unittest/sql/my_apc-t.cc @@ -108,7 +108,6 @@ void *test_apc_service_thread(void *ptr) apc_target.destroy(); mysql_mutex_destroy(&target_mutex); my_thread_end(); - pthread_exit(0); return NULL; }