Properly fail with ESRCH when pthread_killing an exited thread.

Previously, we were callign tgkill(pid, 0, signal) instead, which would
fail with EINVAL instead.

Test: bionic-unit-tests
Change-Id: I25b127dcf347e0223274502b0516a950b6c2093e
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index fc8945c..e68f1ff 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -31,6 +31,7 @@
 #include <unwind.h>
 
 #include <atomic>
+#include <future>
 #include <vector>
 
 #include <android-base/parseint.h>
@@ -539,6 +540,25 @@
   ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
 }
 
+TEST(pthread, pthread_kill__exited_thread) {
+  static std::promise<pid_t> tid_promise;
+  pthread_t thread;
+  ASSERT_EQ(0, pthread_create(&thread, nullptr,
+                              [](void*) -> void* {
+                                tid_promise.set_value(gettid());
+                                return nullptr;
+                              },
+                              nullptr));
+
+  pid_t tid = tid_promise.get_future().get();
+  while (TEMP_FAILURE_RETRY(syscall(__NR_tgkill, getpid(), tid, 0)) != -1) {
+    continue;
+  }
+  ASSERT_EQ(ESRCH, errno);
+
+  ASSERT_EQ(ESRCH, pthread_kill(thread, 0));
+}
+
 TEST_F(pthread_DeathTest, pthread_detach__no_such_thread) {
   pthread_t dead_thread;
   MakeDeadThread(dead_thread);