Permalink
Browse files

Defer thread creation in parsebypart example

  • Loading branch information...
1 parent f54b0e4 commit 0f9dbe0a9c78b6a8163e47a4b5e1c5df7a3360b9 @miloyip committed Aug 29, 2016
Showing with 5 additions and 2 deletions.
  1. +5 −2 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())

0 comments on commit 0f9dbe0

Please sign in to comment.