diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2010-01-20 21:09:30 +0000 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2010-01-20 21:09:30 +0000 |
commit | 23787403e03ea97653aeafcd6ae898b21991de3b (patch) | |
tree | f4f8e267c9e95c1e0c0ad2a5a9714318c880518c /gdb/testsuite | |
parent | ec8ebe726b1f2d43d19256f8d8b33a6dca71537a (diff) | |
download | gdb-23787403e03ea97653aeafcd6ae898b21991de3b.zip gdb-23787403e03ea97653aeafcd6ae898b21991de3b.tar.gz gdb-23787403e03ea97653aeafcd6ae898b21991de3b.tar.bz2 |
gdb/testsuite/
* gdb.threads/watchthreads-reorder.c (gdbstop_mutex): Remove.
(thread1_func): Protect thread1_tid with thread1_tid_cond by
thread1_tid_mutex. Remove gdbstop_mutex handling.
(thread2_func): Protect thread2_tid with thread2_tid_cond by
thread2_tid_mutex. Remove gdbstop_mutex handling.
(main): Move thread1_tid_mutex and thread2_tid_mutex locks before
pthread_create. Remove gdbstop_mutex handling. New comment. Replace
pthread_cond_wait conditionalizations by while loops.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 11 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/watchthreads-reorder.c | 41 |
2 files changed, 29 insertions, 23 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3422558..cd8a7db 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2010-01-20 Jan Kratochvil <jan.kratochvil@redhat.com> + + * gdb.threads/watchthreads-reorder.c (gdbstop_mutex): Remove. + (thread1_func): Protect thread1_tid with thread1_tid_cond by + thread1_tid_mutex. Remove gdbstop_mutex handling. + (thread2_func): Protect thread2_tid with thread2_tid_cond by + thread2_tid_mutex. Remove gdbstop_mutex handling. + (main): Move thread1_tid_mutex and thread2_tid_mutex locks before + pthread_create. Remove gdbstop_mutex handling. New comment. Replace + pthread_cond_wait conditionalizations by while loops. + 2010-01-20 Tom Tromey <tromey@redhat.com> PR backtrace/10770: diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.c b/gdb/testsuite/gdb.threads/watchthreads-reorder.c index c22e296..b8ecde3 100644 --- a/gdb/testsuite/gdb.threads/watchthreads-reorder.c +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c @@ -34,8 +34,6 @@ otherwise. */ #define TIMEOUT (gettid () == getpid() ? 10 : 15) -static pthread_mutex_t gdbstop_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; - static pid_t thread1_tid; static pthread_cond_t thread1_tid_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t thread1_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; @@ -89,13 +87,14 @@ thread1_func (void *unused) int i; volatile int rwatch_store; + timed_mutex_lock (&thread1_tid_mutex); + + /* THREAD1_TID_MUTEX must be already locked to avoid race. */ thread1_tid = gettid (); + i = pthread_cond_signal (&thread1_tid_cond); assert (i == 0); - - /* Be sure GDB is already stopped before continuing. */ - timed_mutex_lock (&gdbstop_mutex); - i = pthread_mutex_unlock (&gdbstop_mutex); + i = pthread_mutex_unlock (&thread1_tid_mutex); assert (i == 0); rwatch_store = thread1_rwatch; @@ -114,13 +113,14 @@ thread2_func (void *unused) int i; volatile int rwatch_store; + timed_mutex_lock (&thread2_tid_mutex); + + /* THREAD2_TID_MUTEX must be already locked to avoid race. */ thread2_tid = gettid (); + i = pthread_cond_signal (&thread2_tid_cond); assert (i == 0); - - /* Be sure GDB is already stopped before continuing. */ - timed_mutex_lock (&gdbstop_mutex); - i = pthread_mutex_unlock (&gdbstop_mutex); + i = pthread_mutex_unlock (&thread2_tid_mutex); assert (i == 0); rwatch_store = thread2_rwatch; @@ -267,7 +267,8 @@ main (int argc, char **argv) setbuf (stdout, NULL); - timed_mutex_lock (&gdbstop_mutex); + timed_mutex_lock (&thread1_tid_mutex); + timed_mutex_lock (&thread2_tid_mutex); timed_mutex_lock (&terminate_mutex); @@ -306,29 +307,23 @@ main (int argc, char **argv) state_wait (tracer, "T (stopped)"); } - timed_mutex_lock (&thread1_tid_mutex); - timed_mutex_lock (&thread2_tid_mutex); - - /* Let the threads start. */ - i = pthread_mutex_unlock (&gdbstop_mutex); - assert (i == 0); + /* Threads are now waiting at timed_mutex_lock (thread1_tid_mutex) and so + they could not trigger the watchpoints before GDB gets unstopped later. + Threads get resumed at pthread_cond_wait below. Use `while' loops for + protection against spurious pthread_cond_wait wakeups. */ printf ("Waiting till the threads initialize their TIDs.\n"); - if (thread1_tid == 0) + while (thread1_tid == 0) { i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex); assert (i == 0); - - assert (thread1_tid > 0); } - if (thread2_tid == 0) + while (thread2_tid == 0) { i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex); assert (i == 0); - - assert (thread2_tid > 0); } printf ("Thread 1 TID = %lu, thread 2 TID = %lu, PID = %lu.\n", |