Index: test/functionalities/watchpoint/hello_watchlocation/main.cpp =================================================================== --- test/functionalities/watchpoint/hello_watchlocation/main.cpp +++ test/functionalities/watchpoint/hello_watchlocation/main.cpp @@ -18,11 +18,24 @@ pthread_t g_thread_2 = NULL; pthread_t g_thread_3 = NULL; -pthread_barrier_t g_barrier; +pthread_mutex_t g_mutex; +pthread_cond_t g_cond; +int g_count; char *g_char_ptr = NULL; void +barrier_wait() +{ + pthread_mutex_lock(&g_mutex); + if (--g_count == 0) + pthread_cond_broadcast(&g_cond); + else + pthread_cond_wait(&g_cond, &g_mutex); + pthread_mutex_unlock(&g_mutex); +} + +void do_bad_thing_with_location(char *char_ptr, char new_val) { unsigned what = new_val; @@ -54,7 +67,7 @@ uint32_t thread_index = *((uint32_t *)arg); printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); - pthread_barrier_wait(&g_barrier); + barrier_wait(); uint32_t count = 0; uint32_t val; @@ -88,7 +101,9 @@ g_char_ptr = (char *)malloc (1); *g_char_ptr = 0; - pthread_barrier_init(&g_barrier, NULL, 4); + pthread_mutex_init(&g_mutex, NULL); + pthread_cond_init(&g_cond, NULL); + g_count = 4; // Create 3 threads err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1); @@ -96,14 +111,15 @@ 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(&g_barrier); + barrier_wait(); // 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(&g_barrier); + pthread_cond_destroy(&g_cond); + pthread_mutex_destroy(&g_mutex); free(g_char_ptr); return 0;