From 6701b7f1d0d448592cc41a265aa3af4b79e90520 Mon Sep 17 00:00:00 2001 From: seelabs Date: Fri, 22 Jan 2016 12:19:55 -0500 Subject: [PATCH] Do not destroy objects until all threads exit in Stoppable test Objects of class `A` could be destroyed before all their member functions finished running. --- beast/threads/impl/Stoppable.test.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beast/threads/impl/Stoppable.test.cpp b/beast/threads/impl/Stoppable.test.cpp index 14342a28c..842d3d6e5 100644 --- a/beast/threads/impl/Stoppable.test.cpp +++ b/beast/threads/impl/Stoppable.test.cpp @@ -169,7 +169,7 @@ class Stoppable_test class A : public Stoppable { - enum {running, please_stop, have_stopped}; + enum {running, please_stop, stopping, stopped}; D d_; E e_; F f_; @@ -184,12 +184,17 @@ class Stoppable_test , test_(test) , stop_(running) {} + ~A() + { + while (stop_ != stopped) + ; + } void run() { while (stop_ == running) ; - stop_ = have_stopped; + stop_ = stopping; } void onPrepare() override @@ -210,10 +215,11 @@ class Stoppable_test void onChildrenStopped() override { stop_ = please_stop; - while (stop_ != have_stopped) + while (stop_ != stopping) ; Stoppable::stopped(); test_.expect(--test_.count == 1, "A::onChildrenStopped called out of order"); + stop_ = stopped; } };