THRIFT-4084: only join threads if joinable
Client: cpp
Patch: Chris Grebeldinger <cgrebeld@gmail.com>

This closes #1188
diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
index 6adcb68..8afabf9 100644
--- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
+++ b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
@@ -61,7 +61,7 @@
   }
 
   ~BoostThread() {
-    if (!detached_) {
+    if (!detached_ && thread_->joinable()) {
       try {
         join();
       } catch (...) {
diff --git a/lib/cpp/src/thrift/concurrency/StdThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/StdThreadFactory.cpp
index 66c7e75..4fca8da 100644
--- a/lib/cpp/src/thrift/concurrency/StdThreadFactory.cpp
+++ b/lib/cpp/src/thrift/concurrency/StdThreadFactory.cpp
@@ -61,7 +61,7 @@
   }
 
   ~StdThread() {
-    if (!detached_) {
+    if (!detached_ && thread_->joinable()) {
       try {
         join();
       } catch (...) {