Below is the list of changes that have just been committed into a local
5.0 repository of serg. When serg 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 15:23:31+01:00, serg@stripped +1 -0
Bug #24387 Valgrind: my_thread_init
wait till all threads have executed my_thread_end() before exiting main()
mysys/my_thr_init.c@stripped, 2006-11-29 15:23:30+01:00, serg@stripped +28 -10
Bug #24387 Valgrind: my_thread_init
wait till all threads have executed my_thread_end() before exiting main()
# 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: serg
# Host: janus.mylan
# Root: /usr/home/serg/Abk/mysql-5.0
--- 1.31/mysys/my_thr_init.c 2006-11-29 15:23:37 +01:00
+++ 1.32/mysys/my_thr_init.c 2006-11-29 15:23:37 +01:00
@@ -30,7 +30,9 @@
#endif /* USE_TLS */
pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
- THR_LOCK_net, THR_LOCK_charset;
+ THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads;
+pthread_cond_t THR_COND_threads;
+uint THR_thread_count= 0;
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
pthread_mutex_t LOCK_localtime_r;
#endif
@@ -79,7 +81,7 @@
#endif
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
/*
- Set mutex type to "errorcheck" a.k.a "adaptive"
+ Set mutex type to "errorcheck"
*/
pthread_mutexattr_init(&my_errorcheck_mutexattr);
pthread_mutexattr_settype(&my_errorcheck_mutexattr,
@@ -94,6 +96,8 @@
pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST);
+ pthread_mutex_init(&THR_LOCK_threads,MY_MUTEX_INIT_FAST);
+ pthread_cond_init (&THR_COND_threads, NULL);
#if defined( __WIN__) || defined(OS2)
win_pthread_init();
#endif
@@ -114,6 +118,17 @@
void my_thread_global_end(void)
{
+ struct timespec abstime;
+ set_timespec(abstime, 5); /* 5 seconds */
+
+ pthread_mutex_lock(&THR_LOCK_threads);
+ while (THR_thread_count)
+ pthread_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads, &abstime);
+ pthread_mutex_unlock(&THR_LOCK_threads);
+ if (THR_thread_count)
+ fprintf(stderr,"my_thread_global_end(): %d threads didn't exit\n",
+ THR_thread_count);
+
pthread_key_delete(THR_KEY_mysys);
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_fast_mutexattr);
@@ -129,6 +144,8 @@
pthread_mutex_destroy(&THR_LOCK_heap);
pthread_mutex_destroy(&THR_LOCK_net);
pthread_mutex_destroy(&THR_LOCK_charset);
+ pthread_mutex_destroy(&THR_LOCK_threads);
+ pthread_cond_destroy (&THR_COND_threads);
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
pthread_mutex_destroy(&LOCK_localtime_r);
#endif
@@ -154,9 +171,6 @@
#ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self());
#endif
-#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
- pthread_mutex_lock(&THR_LOCK_lock);
-#endif
#if !defined(__WIN__) || defined(USE_TLS)
if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
@@ -174,7 +188,7 @@
}
pthread_setspecific(THR_KEY_mysys,tmp);
-#else
+#else /* defined(__WIN__) && !(defined(USE_TLS) */
/*
Skip initialization if the thread specific variable is already initialized
*/
@@ -182,7 +196,6 @@
goto end;
tmp= &THR_KEY_mysys;
#endif
- tmp->id= ++thread_id;
#if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
tmp->thread_self= (pthread_t)getpid();
#endif
@@ -190,10 +203,11 @@
pthread_cond_init(&tmp->suspend, NULL);
tmp->init= 1;
+ pthread_mutex_lock(&THR_LOCK_threads);
+ tmp->id= ++thread_id;
+ ++THR_thread_count;
+ pthread_mutex_unlock(&THR_LOCK_threads);
end:
-#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
- pthread_mutex_unlock(&THR_LOCK_lock);
-#endif
return error;
}
@@ -232,6 +246,10 @@
#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
pthread_setspecific(THR_KEY_mysys,0);
#endif
+ pthread_mutex_lock(&THR_LOCK_threads);
+ if (--THR_thread_count == 0)
+ pthread_cond_signal(&THR_COND_threads);
+ pthread_mutex_unlock(&THR_LOCK_threads);
}
struct st_my_thread_var *_my_thread_var(void)
| Thread |
|---|
| • bk commit into 5.0 tree (serg:1.2319) BUG#24387 | Sergei Golubchik | 29 Nov |