summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2019-11-12 13:44:29 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-12 13:44:29 -0800
commita7ed673121a1594551fa0dfbece4b065a2a56d80 (patch)
tree48190a0eabae4551974acd747b5d59a466cd66d9
parentfc1046c15d9830f24db7d5b20420a7bf884c1a4a (diff)
parentb33827d11a88d2ebbd740a1aa0424379e6efdb43 (diff)
downloadRxCpp-a7ed673121a1594551fa0dfbece4b065a2a56d80.tar.gz
schedulers: Fix std::thread clean-up race in newthread am: 96616d3ccb
am: b33827d11a Change-Id: Ie78ab34b8d1ec1eb849a054fd0bf05fab1244906
-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](){