[Lldb-commits] [PATCH] Add synchronization to TestWatchLocation.

Chaoren Lin chaorenl at google.com
Thu Feb 26 11:52:22 PST 2015


Hi ovyalov,

There was no guarantee that the three threads haven't already exited by the
time the watchpoint is set.

http://reviews.llvm.org/D7916

Files:
  test/functionalities/watchpoint/hello_watchlocation/main.cpp

Index: test/functionalities/watchpoint/hello_watchlocation/main.cpp
===================================================================
--- test/functionalities/watchpoint/hello_watchlocation/main.cpp
+++ test/functionalities/watchpoint/hello_watchlocation/main.cpp
@@ -17,7 +17,7 @@
 pthread_t g_thread_1 = NULL;
 pthread_t g_thread_2 = NULL;
 pthread_t g_thread_3 = NULL;
-
+pthread_barrier_t barrier;
 char *g_char_ptr = NULL;
 
 void
@@ -51,7 +51,7 @@
 {
     uint32_t thread_index = *((uint32_t *)arg);
     printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index);
-
+    pthread_barrier_wait(&barrier);
     uint32_t count = 0;
     uint32_t val;
     while (count++ < 15)
@@ -83,18 +83,18 @@
 
     g_char_ptr = (char *)malloc (1);
     *g_char_ptr = 0;
-
+    pthread_barrier_init(&barrier, NULL, 4);
     // Create 3 threads
     err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1);
     err = ::pthread_create (&g_thread_2, NULL, thread_func, &thread_index_2);
     err = ::pthread_create (&g_thread_3, NULL, thread_func, &thread_index_3);
 
     printf ("Before turning all three threads loose...\n"); // Set break point at this line.
-
+    pthread_barrier_wait(&barrier);
     // Join all of our threads
     err = ::pthread_join (g_thread_1, &thread_result);
     err = ::pthread_join (g_thread_2, &thread_result);
     err = ::pthread_join (g_thread_3, &thread_result);
-
+    pthread_barrier_destroy(&barrier);
     return 0;
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7916.20786.patch
Type: text/x-patch
Size: 1485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150226/3f166394/attachment.bin>


More information about the lldb-commits mailing list