summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Xie <dxie@google.com>2015-11-11 18:57:14 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-11-11 18:57:14 +0000
commiteebe01b523075c0634b04463c210510f192f154d (patch)
treea9629793df46833e162b346bee6b5228bdcc0673
parent216bff9ff33d74fb7f232045799a93b102a4d2a2 (diff)
parent2010fb6722ea2bd9d07c9f0a3e69eafa3d6114e9 (diff)
downloadbionic-eebe01b523075c0634b04463c210510f192f154d.zip
bionic-eebe01b523075c0634b04463c210510f192f154d.tar.gz
bionic-eebe01b523075c0634b04463c210510f192f154d.tar.bz2
Merge "Fix potential race condition on CTS TC pthread_gettid_np" into marshmallow-cts-dev
am: 2010fb6722 * commit '2010fb6722ea2bd9d07c9f0a3e69eafa3d6114e9': Fix potential race condition on CTS TC pthread_gettid_np
-rwxr-xr-x[-rw-r--r--]tests/pthread_test.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 8ae28d8..f15cdab 100644..100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1244,8 +1244,11 @@ TEST(pthread, pthread_attr_getstack_18908062) {
}
#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
@@ -1256,11 +1259,15 @@ TEST(pthread, pthread_gettid_np) {
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