From 0f9dbe0a9c78b6a8163e47a4b5e1c5df7a3360b9 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 29 Aug 2016 10:17:57 +0800 Subject: [PATCH] Defer thread creation in parsebypart example --- example/parsebyparts/parsebyparts.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/parsebyparts/parsebyparts.cpp b/example/parsebyparts/parsebyparts.cpp index 57eed005de..a377efd4e9 100644 --- a/example/parsebyparts/parsebyparts.cpp +++ b/example/parsebyparts/parsebyparts.cpp @@ -21,12 +21,15 @@ class AsyncDocumentParser { AsyncDocumentParser(Document& d) : stream_(*this) , d_(d) - , parseThread_(&AsyncDocumentParser::Parse, this) + , parseThread_() , mutex_() , notEmpty_() , finish_() , completed_() - {} + { + // Create and execute thread after all member variables are initialized. + parseThread_ = std::thread(&AsyncDocumentParser::Parse, this); + } ~AsyncDocumentParser() { if (!parseThread_.joinable())