summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2019-11-12 13:40:50 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-12 13:40:50 -0800
commitb33827d11a88d2ebbd740a1aa0424379e6efdb43 (patch)
tree48190a0eabae4551974acd747b5d59a466cd66d9
parentfc1046c15d9830f24db7d5b20420a7bf884c1a4a (diff)
parent96616d3ccb430235fe81b84b197cedd499b73373 (diff)
downloadRxCpp-b33827d11a88d2ebbd740a1aa0424379e6efdb43.tar.gz
schedulers: Fix std::thread clean-up race in newthread
am: 96616d3ccb Change-Id: Ief506d7f844ffb0d49c97c67b774b1cd6f06b967
-rw-r--r--Rx/v2/src/rxcpp/schedulers/rx-newthread.hpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/Rx/v2/src/rxcpp/schedulers/rx-newthread.hpp b/Rx/v2/src/rxcpp/schedulers/rx-newthread.hpp
index 5145e92..7c93469 100644
--- a/Rx/v2/src/rxcpp/schedulers/rx-newthread.hpp
+++ b/Rx/v2/src/rxcpp/schedulers/rx-newthread.hpp
@@ -37,6 +37,16 @@ private:
virtual ~new_worker_state()
{
+ // Ensure that std::thread is no longer joinable,
+ // otherwise the destructor will call std::terminate.
+ if (!worker.joinable()) {
+ return;
+ }
+ if (worker.get_id() != std::this_thread::get_id()) {
+ worker.join();
+ } else {
+ worker.detach();
+ }
}
explicit new_worker_state(composite_subscription cs)
@@ -76,13 +86,7 @@ private:
if (!keepAlive->q.empty()) std::terminate();
keepAlive->wake.notify_one();
- if (keepAlive->worker.joinable() && keepAlive->worker.get_id() != std::this_thread::get_id()) {
- guard.unlock();
- keepAlive->worker.join();
- }
- else {
- keepAlive->worker.detach();
- }
+ // ~new_worker_state cleans up the std::thread
});
state->worker = tf([keepAlive](){