diff --git a/include/grpc++/impl/sync_no_cxx11.h b/include/grpc++/impl/sync_no_cxx11.h index 5636373b8141638204ffbb19d30c9f2a3d02fa80..dda939bf715fd247c7e6688388d86dae8ba58cc4 100644 --- a/include/grpc++/impl/sync_no_cxx11.h +++ b/include/grpc++/impl/sync_no_cxx11.h @@ -76,9 +76,9 @@ class lock_guard { template <class mutex> class unique_lock : public lock_guard<mutex> { public: - unique_lock(mutex &mu) : lock_guard(mu) { } - void lock() { lock_internal(); } - void unlock() { unlock_internal(); } + unique_lock(mutex &mu) : lock_guard<mutex>(mu) { } + void lock() { this->lock_internal(); } + void unlock() { this->unlock_internal(); } }; class condition_variable { diff --git a/include/grpc++/impl/thd_no_cxx11.h b/include/grpc++/impl/thd_no_cxx11.h index a01b931df86f6de027ecd111c474b25ab6a5e5ad..a6bdd7dfe9ec68eb21b6d6d72258120dbf4db434 100644 --- a/include/grpc++/impl/thd_no_cxx11.h +++ b/include/grpc++/impl/thd_no_cxx11.h @@ -82,6 +82,10 @@ class thread { thread_function_base *func_; gpr_thd_id thd_; bool joined_; + + // Disallow copy and assign. + thread(const thread&); + void operator=(const thread&); }; } // namespace grpc diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc index e8d0e89ed212da151cbce6bbe2548be2718d290a..118cabcb6127dc86800850d6197e58ef82aeadaa 100644 --- a/src/cpp/server/thread_pool.cc +++ b/src/cpp/server/thread_pool.cc @@ -60,7 +60,7 @@ void ThreadPool::ThreadFunc() { ThreadPool::ThreadPool(int num_threads) : shutdown_(false) { for (int i = 0; i < num_threads; i++) { - threads_.push_back(grpc::thread(&ThreadPool::ThreadFunc, this)); + threads_.push_back(new grpc::thread(&ThreadPool::ThreadFunc, this)); } } @@ -71,7 +71,8 @@ ThreadPool::~ThreadPool() { cv_.notify_all(); } for (auto t = threads_.begin(); t != threads_.end(); t++) { - t->join(); + (*t)->join(); + delete *t; } } diff --git a/src/cpp/server/thread_pool.h b/src/cpp/server/thread_pool.h index 0f24d6e9b32de02c74d69f85cd794e0373e4a4a2..26f25611b5ebf9cccc509fe4fafcd69cccdcd0de 100644 --- a/src/cpp/server/thread_pool.h +++ b/src/cpp/server/thread_pool.h @@ -57,7 +57,7 @@ class ThreadPool GRPC_FINAL : public ThreadPoolInterface { grpc::condition_variable cv_; bool shutdown_; std::queue<std::function<void()>> callbacks_; - std::vector<grpc::thread> threads_; + std::vector<grpc::thread*> threads_; void ThreadFunc(); }; diff --git a/test/core/support/tls_test.c b/test/core/support/tls_test.c index 8632fd44901dfea5f407d4394f07a30e2c76703d..0a3c28417f6a249af435bb0775949d1cf1743c2f 100644 --- a/test/core/support/tls_test.c +++ b/test/core/support/tls_test.c @@ -54,6 +54,7 @@ static void thd_body(void *arg) { gpr_tls_set(&test_var, i); GPR_ASSERT(gpr_tls_get(&test_var) == i); } + gpr_tls_set(&test_var, 0); } /* ------------------------------------------------- */ diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 7a15591b44b452948febe3f7be2711156b1eed54..f48cf953a4f6e60e7e8a38c241daef3beafcff96 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -31,6 +31,7 @@ * */ +#include <mutex> #include <thread> #include "src/core/security/credentials.h" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 310227a29c8c29196cf47ee62eda2971cc151c0f..5ee29e40f43eb97a0e563e62e8fa57ff52f59faf 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -31,6 +31,7 @@ * */ +#include <mutex> #include <thread> #include "test/core/util/port.h"