diff options
author | rafal@quant.(none) <> | 2006-12-08 11:41:12 +0100 |
---|---|---|
committer | rafal@quant.(none) <> | 2006-12-08 11:41:12 +0100 |
commit | 5d7af856f769a77b398de64597458eca252ef43c (patch) | |
tree | 6702b694b87c0c4963a83e478d5b342845c9f240 /mysys | |
parent | 3406fcea39defef5d5cd92f99fa4e60d556f3dae (diff) | |
download | mariadb-git-5d7af856f769a77b398de64597458eca252ef43c.tar.gz |
BUG#24507 (rpl_log.test crash slave):
The problem was located to lie inside current NPTL pthread_exit()
implementation. Race conditions in this code can lead to segmentation
fault. Hovewer, this can happen only in a race between first thread
calling pthread_exit() and other threads.
Workaround implemented in this patch spawns a dummy thread, which
exits immediately, during thread lib initialization. This will exclude
segment violations when further threads exit.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_thr_init.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 4d23d01cd82..6663af986dd 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -44,6 +44,23 @@ pthread_mutexattr_t my_fast_mutexattr; pthread_mutexattr_t my_errorcheck_mutexattr; #endif +#ifdef NPTL_PTHREAD_EXIT_BUG /* see my_pthread.h */ + +/* + Dummy thread spawned in my_thread_global_init() below to avoid + race conditions in NPTL pthread_exit code. +*/ + +static +pthread_handler_t nptl_pthread_exit_hack_handler(void *arg) +{ + /* Do nothing! */ + pthread_exit(0); + return 0; +} + +#endif + /* initialize thread environment @@ -62,6 +79,28 @@ my_bool my_thread_global_init(void) fprintf(stderr,"Can't initialize threads: error %d\n",errno); return 1; } + +#ifdef NPTL_PTHREAD_EXIT_BUG + +/* + BUG#24507: Race conditions inside current NPTL pthread_exit() implementation. + + To avoid a possible segmentation fault during concurrent executions of + pthread_exit(), a dummy thread is spawned which initializes internal variables + of pthread lib. See bug description for thoroughfull explanation. + + TODO: Remove this code when fixed versions of glibc6 are in common use. +*/ + + pthread_t dummy_thread; + pthread_attr_t dummy_thread_attr; + + pthread_attr_init(&dummy_thread_attr); + pthread_attr_setdetachstate(&dummy_thread_attr,PTHREAD_CREATE_DETACHED); + + pthread_create(&dummy_thread,&dummy_thread_attr,nptl_pthread_exit_hack_handler,NULL); + +#endif #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP /* |