summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-03-19 15:19:25 -0700
committerYabin Cui <yabinc@google.com>2015-03-19 16:48:19 -0700
commitbbb0432a33787f1a627abb396fe343a7943ac7bc (patch)
tree356c2b33690b7c1e43c4d5a4ba46d0553b1e06f6
parent7875b506edfb1fe593034eaf4bc9aa156179fbd2 (diff)
downloadbionic-bbb0432a33787f1a627abb396fe343a7943ac7bc.zip
bionic-bbb0432a33787f1a627abb396fe343a7943ac7bc.tar.gz
bionic-bbb0432a33787f1a627abb396fe343a7943ac7bc.tar.bz2
Return EINVAL when calling pthread_detach for joined thread.
Change-Id: I717015132187e087e0ad485284a13c8801e25e77
-rw-r--r--libc/bionic/pthread_detach.cpp2
-rw-r--r--tests/pthread_test.cpp5
2 files changed, 5 insertions, 2 deletions
diff --git a/libc/bionic/pthread_detach.cpp b/libc/bionic/pthread_detach.cpp
index 9f957f4..dcdb7b1 100644
--- a/libc/bionic/pthread_detach.cpp
+++ b/libc/bionic/pthread_detach.cpp
@@ -44,7 +44,7 @@ int pthread_detach(pthread_t t) {
}
switch (old_state) {
case THREAD_NOT_JOINED: return 0;
- case THREAD_JOINED: return 0; // Already being joined; silently do nothing, like glibc.
+ case THREAD_JOINED: return EINVAL;
case THREAD_DETACHED: return EINVAL;
case THREAD_EXITED_NOT_JOINED: break; // Call pthread_join out of scope of pthread_accessor.
}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index de60f28..251a230 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -271,8 +271,11 @@ TEST(pthread, pthread_no_op_detach_after_join) {
sleep(1); // (Give t2 a chance to call pthread_join.)
- // ...a call to pthread_detach on thread 1 will "succeed" (silently fail)...
+#if defined(__BIONIC__)
+ ASSERT_EQ(EINVAL, pthread_detach(t1));
+#else
ASSERT_EQ(0, pthread_detach(t1));
+#endif
AssertDetached(t1, false);
spinhelper.UnSpin();