Merge "Fix potential race condition on CTS TC pthread_gettid_np" into marshmallow-cts-dev am: 2010fb6722
am: eebe01b523

* commit 'eebe01b523075c0634b04463c210510f192f154d':
  Fix potential race condition on CTS TC pthread_gettid_np
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
old mode 100644
new mode 100755
index ad8fac6..e210255
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1245,8 +1245,11 @@
 }
 
 #if defined(__BIONIC__)
+static pthread_mutex_t gettid_mutex;
 static void* pthread_gettid_np_helper(void* arg) {
+  pthread_mutex_lock(&gettid_mutex);
   *reinterpret_cast<pid_t*>(arg) = gettid();
+  pthread_mutex_unlock(&gettid_mutex);
   return NULL;
 }
 #endif
@@ -1257,11 +1260,15 @@
 
   pid_t t_gettid_result;
   pthread_t t;
+  pthread_mutex_init(&gettid_mutex, NULL);
+  pthread_mutex_lock(&gettid_mutex);
   pthread_create(&t, NULL, pthread_gettid_np_helper, &t_gettid_result);
 
   pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
+  pthread_mutex_unlock(&gettid_mutex);
 
   pthread_join(t, NULL);
+  pthread_mutex_destroy(&gettid_mutex);
 
   ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
 #else