List:Commits« Previous MessageNext Message »
From:rsomla Date:November 29 2006 5:11pm
Subject:bk commit into 5.0 tree (rafal:1.2323) BUG#24507
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of rafal. When rafal does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-11-29 18:11:24+01:00, rafal@quant.(none) +2 -0
  BUG#24507 (rpl_log.test crash slave):
  
  The problem was located to lie inside current NTPL pthread_exit() 
  implementation. Race conditions in this code can lead to segmentation
  fault. Hovewer, this can happen only in a rece 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.
   

  include/my_pthread.h@stripped, 2006-11-29 18:11:20+01:00, rafal@quant.(none) +17 -0
    define macro NTPL_PTHREAD_EXIT_HACK which controls whethre workaround
    in my_thread_global_init() is included or not.

  mysys/my_thr_init.c@stripped, 2006-11-29 18:11:21+01:00, rafal@quant.(none) +38 -0
    Spawn a dummy thread in my_thread_global_init() to initialize pthread 
    lib internal variables.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	rafal
# Host:	quant.(none)
# Root:	/ext/mysql/bk/mysql-5.0-bug24507

--- 1.91/include/my_pthread.h	2006-11-29 18:11:28 +01:00
+++ 1.92/include/my_pthread.h	2006-11-29 18:11:28 +01:00
@@ -31,6 +31,23 @@
 #define EXTERNC
 #endif /* __cplusplus */ 
 
+/*
+  BUG#24507: Race conditions inside current NPTL pthread_exit() implementation.
+  
+  If macro NTPL_PTHREAD_EXIT_HACK is defined then a hack described in the bug
+  report will be implemented inside my_thread_global_init() in my_thr_init.c.
+   
+  This amounts to spawning a dummy thread which does nothing but executes 
+  pthread_exit(0). 
+  
+  This code should be removed when fixed versions of glibc6 are in common use. 
+ */
+
+#if defined(HAVE_NTPL) && defined(TARGET_OS_LINUX)
+#define NTPL_PTHREAD_EXIT_HACK	1
+#endif 
+
+
 #if defined(__WIN__) || defined(OS2)
 
 #ifdef OS2

--- 1.31/mysys/my_thr_init.c	2006-11-29 18:11:28 +01:00
+++ 1.32/mysys/my_thr_init.c	2006-11-29 18:11:28 +01:00
@@ -44,6 +44,22 @@
 pthread_mutexattr_t my_errorcheck_mutexattr;
 #endif
 
+#ifdef NTPL_PTHREAD_EXIT_HACK /* see my_pthread.h */
+
+/*
+ Dummy thread spawned in my_thread_global_init() below to avoid
+ race conditions in NTPL pthreads code.
+*/
+
+pthread_handler_t dummy_thread_handler(void *arg)
+{
+  /* Do nothing! */
+  pthread_exit(0);
+  return 0;
+}
+
+#endif
+
 /*
   initialize thread environment
 
@@ -62,6 +78,28 @@
     fprintf(stderr,"Can't initialize threads: error %d\n",errno);
     return 1;
   }
+
+#ifdef NTPL_PTHREAD_EXIT_HACK 
+
+/*
+  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. 
+  
+  This code should be removed 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,dummy_thread_handler,NULL);
+
+#endif
 
 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
   /*
Thread
bk commit into 5.0 tree (rafal:1.2323) BUG#24507rsomla29 Nov