Fix the race in gdb.threads/staticthreads.exp
authorYao Qi <yao@codesourcery.com>
Thu, 5 Jun 2014 07:07:47 +0000 (15:07 +0800)
committerYao Qi <yao@codesourcery.com>
Fri, 6 Jun 2014 01:45:22 +0000 (09:45 +0800)
The code in gdb.threads/staticthreads.exp about checking the value of
tlsvar in main thread is racy, because when child thread hits
breakpoint, the main thread may not go into pthread_join yet, and
may not be unwind to main.

This patch is to move the line setting breakpoint on after sem_wait,
so that the child thread will hit breakpoint after main thread calls
sem_post.  IOW, when child thread hits breakpoint, the main thread is
in either sem_post or pthread_join.  "up 10" can unwind main thread to
main.

gdb/testsuite:

2014-06-06  Yao Qi  <yao@codesourcery.com>

* gdb.threads/staticthreads.c (thread_function): Move the line
setting breakpoint on forward.
* gdb.threads/staticthreads.exp: Update comments.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/staticthreads.c
gdb/testsuite/gdb.threads/staticthreads.exp

index 83c57e0b7ffefeecbb5800e459a91d49eb01e359..51686d19ad93175f0974b14a9bbed41e6d087305 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-06  Yao Qi  <yao@codesourcery.com>
+
+       * gdb.threads/staticthreads.c (thread_function): Move the line
+       setting breakpoint on forward.
+       * gdb.threads/staticthreads.exp: Update comments.
+
 2014-06-05  Ludovic Courtès  <ludo@gnu.org>
 
        * gdb.guile/scm-value.exp (test_value_in_inferior): Add test
index 5c8eabea47ed6f1e40c434f668562e9c1ff273a4..db78063cec7eecfbef74c9bd9febbad3a0ac1b58 100644 (file)
@@ -38,7 +38,6 @@ thread_function (void *arg)
 #ifdef HAVE_TLS
   tlsvar = 2;
 #endif
-  printf ("Thread executing\n"); /* tlsvar-is-set */
   while (sem_wait (&semaphore) != 0)
     {
       if (errno != EINTR)
@@ -47,6 +46,7 @@ thread_function (void *arg)
          return NULL;
        }
     }
+  printf ("Thread executing\n"); /* tlsvar-is-set */
   return NULL;
 }
 
index 9fa625a83ca047d3a3891d02adaaa6c16868e953..bdc03d431664690a95a7fedc5a40b5573f9a7638 100644 (file)
@@ -105,7 +105,7 @@ if { "$have_tls" != "" } {
     gdb_continue_to_breakpoint "tlsvar-is-set" ".* tlsvar-is-set .*"
     gdb_test "p tlsvar" " = 2" "tlsvar in thread"
     gdb_test "thread 1" ".*"
-    # Unwind from pthread_join.
+    # Unwind to main.
     gdb_test "up 10" " in main .*"
     gdb_test "p tlsvar" " = 1" "tlsvar in main"
 }
This page took 0.035224 seconds and 4 git commands to generate.