{"id":297301,"date":"2020-01-18T09:00:09","date_gmt":"2020-01-18T09:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297301"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-01-18T09:00:09","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297301","title":{"rendered":"\u0421\u043a\u0430\u0437 \u043e\u0431 \u043e\u043f\u0430\u0441\u043d\u043e\u043c std::enable_shared_from_this, \u0438\u043b\u0438 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb \u2014 \u0440\u0430\u0437\u0431\u043e\u0440 \u043f\u043e\u043b\u0451\u0442\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/478190\/\">\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u043e\u0440 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438: <a href=\"https:\/\/habr.com\/ru\/post\/471326\/\">\u0421\u043a\u0430\u0437 \u043e\u0431 \u043e\u043f\u0430\u0441\u043d\u043e\u043c std::enable_shared_from_this, \u0438\u043b\u0438 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb<\/a>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412\u0435\u0441\u044c \u043a\u043e\u0434, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/ADDubovik\/Zomby_antipattern_concept\" rel=\"nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a> \u0432 \u0432\u0435\u0442\u043a\u0430\u0445. \u0412 \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432 C++17 \u2014 weak_from_this(), if statement with init-statement, \u043c\u043e\u0436\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451 \u043f\u043e \u043c\u0435\u043b\u043e\u0447\u0438.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<br \/>   \u2014 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e (\u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e) \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430;<br \/>   \u2014 \u0434\u043b\u044f \u043f\u0440\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (std::thread);<br \/>   \u2014 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430;<br \/>   \u2014 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430;<br \/>   \u2014 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0445\u0432\u0430\u0442 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 shared_from_this;<br \/>   \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0442\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430. \u0423\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u0441\u0435\u0445 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u044b\u0437\u043e\u0432\u0443 \u0435\u0433\u043e \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 RAII \u043d\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442. \u041f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442:<br \/>   \u2014 \u0442\u0440\u0443\u0434\u043d\u043e\u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0443\u0442\u0435\u0447\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 (\u0432\u0441\u0435\u0433\u0434\u0430);<br \/>   \u2014 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f);<br \/>   \u2014 \u0441\u0431\u043e\u0439 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f).<br \/>  \u0412\u043e\u0442 \u044d\u0442\u0443 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0438 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c.<\/p>\n<h2>\u0421\u043f\u043e\u0441\u043e\u0431 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439, \u0438\u043b\u0438 weak<\/h2>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u043e\u0439 \u0435\u0451 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 std::weak_ptr.<\/p>\n<p>  <b>\u0418\u0434\u0435\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/b> \u043b\u044f\u043c\u0431\u0434\u0430, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c weak_from_this(), \u0430 \u043d\u0435 shared_from_this(). \u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043e\u043c\u0431\u0438, \u0438 \u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0431\u0435\u0437 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<h4>SimpleZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         while (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         while (auto shis = whis.lock()) {             if (shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {                 shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));                 std::this_thread::sleep_for(std::chrono::seconds(1));             }         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u043e\u0434 <b>\u0432\u0440\u043e\u0434\u0435 \u0431\u044b<\/b> \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u2014 \u0437\u043e\u043c\u0431\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<br \/>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0441\u0442\u0430\u043b \u043b\u0438\u0448\u043d\u0438\u043c (\u0445\u043e\u0442\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d \u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b) \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u043e\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0439 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a std::shared_ptr. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430 \u043e\u0442 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u2014 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 runOnce, \u0445\u043e\u0442\u044f \u0438 \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 _listener.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         while (auto shis = whis.lock()) {             if (shis-&gt;_listener) {                 shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));                 std::this_thread::sleep_for(std::chrono::seconds(1));             }         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0435\u043b\u0435 \u043b\u044f\u043c\u0431\u0434\u044b \u0441\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u2014 \u0432\u0441\u0451 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 sleep_for.<\/p>\n<p>  \u0423\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         while (auto shis = whis.lock()) {             if (shis-&gt;_listener) {                 shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));                 shis.reset();                 std::this_thread::sleep_for(std::chrono::seconds(1));             }         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         while (true) {             if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {                 shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             } else {                 break;             }             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0447\u0442\u043e, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443?<br \/>  \u041a\u0430\u043a \u0431\u044b \u043d\u0435 \u0442\u0430\u043a!<br \/>  \u0423 \u043d\u0430\u0441 \u0442\u0443\u0442 \u0433\u043e\u043d\u043a\u0430.<br \/>  \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0435\u0451 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u0441\u043b\u0438\u043f\u0430 \u0432 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         while (true) {             if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) { \/*!!!*\/         std::this_thread::sleep_for(std::chrono::seconds(1));                 shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             } else {                 break;             }         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  SimpleZomby is alive!<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th>main thread<\/th>\n<th>zomby thread<\/th>\n<\/tr>\n<tr>\n<td>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 runOnce<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043b\u0430\u0431\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u0437\u044f\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e<\/td>\n<\/tr>\n<tr>\n<td>\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0441\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 listener&#8217;\u0443<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>  \u0417\u043e\u043c\u0431\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f.<br \/>  \u041d\u043e \u0432\u0441\u0451 \u0435\u0449\u0451 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u043e\u0437\u0434\u043d\u043e \u2014 \u043e\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u043e\u043c\u0431\u0438 \u043f\u0440\u0438\u0448\u043b\u043e \u043e\u0434\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<br \/>  \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u043a \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u043c, \u0442\u0430\u043a \u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u043c \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439.<\/p>\n<p>  <b>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 listener \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c?<\/b><br \/>  \u0417\u043e\u043c\u0431\u0438 \u0432\u0440\u044f\u0434 \u043b\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u0433\u0440\u043e\u043a\u043e\u043c \u043d\u0430 \u043f\u043e\u043b\u0435.<br \/>  \u0414\u0430\u043d\u043d\u044b\u0435, \u043f\u0440\u0438\u0445\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 (\u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0443, \u043f\u0430\u0440\u0441\u0438\u043d\u0433, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0438 \u0442.\u043f.). \u0423\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0437\u043e\u043c\u0431\u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u044b. \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0433\u0440\u043e\u0437\u0438\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u0437\u043e\u043c\u0431\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u0443\u044e \u043e\u0442\u0432\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043a\u0446\u0438\u044e. \u0412\u0440\u044f\u0434 \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u0440\u0430\u0434\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044e <b>\u00ab\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u00bb<\/b> \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438 <b>\u00ab\u041e\u0442\u043c\u0435\u043d\u0430\u00bb<\/b>.<\/p>\n<h4>SteppingZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SteppingZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SteppingZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;resolveDnsName();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;connectTcp();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;establishSsl();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;sendHttpRequest();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;readHttpReply();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>N13SteppingZomby5ZombyE::resolveDnsName started<br \/>  N13SteppingZomby5ZombyE::resolveDnsName finished<br \/>  N13SteppingZomby5ZombyE::connectTcp started<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N13SteppingZomby5ZombyE::connectTcp finished<br \/>  N13SteppingZomby5ZombyE::establishSsl started<br \/>  N13SteppingZomby5ZombyE::establishSsl finished<br \/>  N13SteppingZomby5ZombyE::sendHttpRequest started<br \/>  N13SteppingZomby5ZombyE::sendHttpRequest finished<br \/>  N13SteppingZomby5ZombyE::readHttpReply started<br \/>  N13SteppingZomby5ZombyE::readHttpReply finished<br \/>  N13SteppingZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e (\u043d\u0435\u043d\u0443\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u0441\u0440\u0430\u0437\u0443 \u0443\u0431\u0438\u0440\u0430\u0435\u043c):  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SteppingZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SteppingZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()](){         if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {             shis-&gt;resolveDnsName();         }         if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {             shis-&gt;connectTcp();         }         if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {             shis-&gt;establishSsl();         }         if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {             shis-&gt;sendHttpRequest();         }         if (auto shis = whis.lock(); shis &amp;&amp; shis-&gt;_listener) {             shis-&gt;readHttpReply();         }     }); }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>N13SteppingZomby5ZombyE::resolveDnsName started<br \/>  N13SteppingZomby5ZombyE::resolveDnsName finished<br \/>  N13SteppingZomby5ZombyE::connectTcp started<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N13SteppingZomby5ZombyE::connectTcp finished<br \/>  N13SteppingZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 SimpleZomby:<br \/>   \u2014 <b>\u0432\u0440\u043e\u0434\u0435 \u0431\u044b<\/b> \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043e\u043c\u0431\u0438;<br \/>   \u2014 \u0441\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 resolveDnsName, connectTcp, establishSsl, sendHttpRequest, readHttpReply \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430;<br \/>   \u2014 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438.<br \/>  \u041d\u0430\u0447\u0430\u0442\u044b\u0439 \u0448\u0430\u0433 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 listener, \u043d\u043e <b>\u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0448\u0430\u0433\u043e\u0432<\/b> \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u0430 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u2014 \u043a\u0440\u043e\u043c\u0435 \u0441\u043b\u0443\u0447\u0430\u044f \u0433\u043e\u043d\u043a\u0438, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0451 \u0436\u0435 \u043d\u0430\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438.<br \/>  \u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 private-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438.<\/p>\n<h4>BoozdedZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">BoozdedZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;BoozdedZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()]() {         while (shis &amp;&amp; shis-&gt;_semaphore &amp;&amp; shis-&gt;_listener) {             auto handler = [shis](auto errorCode) {                 if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; errorCode == boozd::azzio::io_context::error_code::no_error) {                     std::ostringstream buf;                     buf &lt;&lt; &quot;BoozdedZomby has got a fresh data: &quot;;                     for (auto const &elem; : shis-&gt;_buffer)                         buf &lt;&lt; elem &lt;&lt; ' ';                     buf &lt;&lt; std::endl;                      shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));                 }             };             shis-&gt;_buffer.clear();             shis-&gt;_context.async_read(shis-&gt;_stream, shis-&gt;_buffer, handler);             shis-&gt;_context.run();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>BoozdedZomby has got a fresh data: 1144108930 101027544 1458777923 1115438165 74243042 <br \/>  BoozdedZomby has got a fresh data: 143542612 1131570933 <br \/>  BoozdedZomby has got a fresh data: 893351816 563613512 704877633 <br \/>  BoozdedZomby has got a fresh data: 1551901393 1399125485 1899894091 937186357 590357944 357571490 <br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  BoozdedZomby has got a fresh data: 1927702196 130060903 1083454666 2118797801 2035308228 824938981 <br \/>  BoozdedZomby has got a fresh data: 2020739063 1635339425 34075629 <br \/>  BoozdedZomby has got a fresh data: 2146319451 500782188 1269406752 884936716 892053144 <br \/>  BoozdedZomby has got a fresh data: 330111137 1723153177 1070477904 <br \/>  BoozdedZomby has got a fresh data: 343098142 280090412 589673557 889688008 2014119113 388471006   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">BoozdedZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;BoozdedZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([whis = weak_from_this()]() {         while (auto shis = whis.lock()) {             if (shis-&gt;_semaphore &amp;&amp; shis-&gt;_listener) {                 auto handler = [whis](auto errorCode) {                     auto shis = whis.lock();                     if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; errorCode == boozd::azzio::io_context::error_code::no_error) {                         std::ostringstream buf;                         buf &lt;&lt; &quot;BoozdedZomby has got a fresh data: &quot;;                         for (auto const &elem; : shis-&gt;_buffer)                             buf &lt;&lt; elem &lt;&lt; ' ';                         buf &lt;&lt; std::endl;                          shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));                     }                 };                 shis-&gt;_buffer.clear();                 shis-&gt;_context.async_read(shis-&gt;_stream, shis-&gt;_buffer, handler);                 shis-&gt;_context.run();             }         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>BoozdedZomby has got a fresh data: 1144108930 101027544 1458777923 1115438165 74243042 <br \/>  BoozdedZomby has got a fresh data: 143542612 1131570933 <br \/>  BoozdedZomby has got a fresh data: 893351816 563613512 704877633 <br \/>  BoozdedZomby has got a fresh data: 1551901393 1399125485 1899894091 937186357 590357944 357571490 <br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  BoozdedZomby has got a fresh data: 1927702196 130060903 1083454666 2118797801 2035308228 824938981 <br \/>  N12BoozdedZomby5ZombyE::~Zomby<br \/>  N5boozd5azzio10io_contextE::~io_context<br \/>  N5boozd5azzio13random_streamE::~random_stream<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u043e\u043c\u0431\u0438-\u043f\u043e\u0442\u043e\u043a \u043e\u0442\u0434\u0430\u0451\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 boozd::azzio::io_context::run(). \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u043a\u043e\u043b\u043b\u0431\u044d\u043a-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 run(). \u041a\u043e\u043b\u043b\u0431\u044d\u043a-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043f\u0440\u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u043e\u043d\u0430 \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f listener&#8217;\u043e\u043c.<br \/>  \u0412 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u044b \u043e\u043d\u0438 \u0435\u0449\u0451 \u0441\u0438\u043b\u044c\u043d\u0435\u0435: BoozdedZomby \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0448\u044c \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u044f\u0432\u0438\u0442\u044c, \u0447\u0442\u043e <b>\u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b<\/b>. \u041e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u0430 \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 \u043f\u043e weak-\u0441\u043f\u043e\u0441\u043e\u0431\u0443<\/h3>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043e\u043c\u0431\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u043d\u044b \u0437\u0430\u0445\u0432\u0430\u0442\u0430 shared_from_this \u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442 weak_from_this:<br \/>   \u2014 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0440\u0438\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e (\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b);<br \/>   \u2014 \u043d\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 (\u0432\u0437\u0430\u0438\u043c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u0434\u0432\u0443\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u0443\u0434\u0443\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0432 listener \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u043e\u043c\u0431\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439).<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u043e\u043c\u0431\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u2014 \u0438 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043b\u0433\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. <\/p>\n<p>  \u0412\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0440\u043e\u043b\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>  \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0433\u043e\u043d\u043a\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0437\u043e\u043c\u0431\u0438 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u0442\u0432\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u043b\u0438 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u0435\u0440\u043f\u0438\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f (\u0435\u0449\u0451 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443).<\/p>\n<h2>\u0421\u043f\u043e\u0441\u043e\u0431 \u0447\u0435\u0441\u0442\u043d\u044b\u0439, \u0438\u043b\u0438 use_count<\/h2>\n<p>  <b>\u0418\u0434\u0435\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/b> \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c shared_from_this, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c std::shared_ptr::use_count().<\/p>\n<p>  <b>\u041f\u043e\u0447\u0435\u043c\u0443 \u0447\u0435\u0441\u0442\u043d\u044b\u0439?<\/b><br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 weak_from_this \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0438\u043b\u043b\u044e\u0437\u0438\u044e \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u0432\u043b\u0438\u044f\u043d\u0438\u044f \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438. \u0410 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u2014 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u043e\u0431\u043c\u0430\u043d\u0430, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 <b>\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442<\/b> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a.<\/p>\n<h4>SimpleZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         while (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         while (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 weak-\u0441\u043f\u043e\u0441\u043e\u0431\u0430:<br \/>   \u2014 \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0441\u0442\u0430\u043b \u043b\u0438\u0448\u043d\u0438\u043c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430;<br \/>   \u2014 \u0437\u043e\u043c\u0431\u0438 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c, \u043d\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 use_count() \u0432 \u0437\u043e\u043c\u0431\u0438-\u043f\u043e\u0442\u043e\u043a\u0435 \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0441\u044b\u043b\u043a\u0438).<\/p>\n<h4>SteppingZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SteppingZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SteppingZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;resolveDnsName();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;connectTcp();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;establishSsl();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;sendHttpRequest();         }         if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;readHttpReply();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>N13SteppingZomby5ZombyE::resolveDnsName started<br \/>  N13SteppingZomby5ZombyE::resolveDnsName finished<br \/>  N13SteppingZomby5ZombyE::connectTcp started<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N13SteppingZomby5ZombyE::connectTcp finished<br \/>  N13SteppingZomby5ZombyE::establishSsl started<br \/>  N13SteppingZomby5ZombyE::establishSsl finished<br \/>  N13SteppingZomby5ZombyE::sendHttpRequest started<br \/>  N13SteppingZomby5ZombyE::sendHttpRequest finished<br \/>  N13SteppingZomby5ZombyE::readHttpReply started<br \/>  N13SteppingZomby5ZombyE::readHttpReply finished<br \/>  N13SteppingZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SteppingZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SteppingZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;resolveDnsName();         }         if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;connectTcp();         }         if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;establishSsl();         }         if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;sendHttpRequest();         }         if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;readHttpReply();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>N13SteppingZomby5ZombyE::resolveDnsName started<br \/>  N13SteppingZomby5ZombyE::resolveDnsName finished<br \/>  N13SteppingZomby5ZombyE::connectTcp started<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N13SteppingZomby5ZombyE::connectTcp finished<br \/>  N13SteppingZomby5ZombyE::~Zomby<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u0441\u0451 \u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043a \u0432 weak-\u0441\u043f\u043e\u0441\u043e\u0431\u0435.<\/p>\n<h4>BoozdedZomby<\/h4>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">BoozdedZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;BoozdedZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()]() {         while (shis &amp;&amp; shis-&gt;_semaphore &amp;&amp; shis-&gt;_listener) {             auto handler = [shis](auto errorCode) {                 if (shis &amp;&amp; shis-&gt;_listener &amp;&amp; errorCode == boozd::azzio::io_context::error_code::no_error) {                     std::ostringstream buf;                     buf &lt;&lt; &quot;BoozdedZomby has got a fresh data: &quot;;                     for (auto const &elem; : shis-&gt;_buffer)                         buf &lt;&lt; elem &lt;&lt; ' ';                     buf &lt;&lt; std::endl;                      shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));                 }             };             shis-&gt;_buffer.clear();             shis-&gt;_context.async_read(shis-&gt;_stream, shis-&gt;_buffer, handler);             shis-&gt;_context.run();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>BoozdedZomby has got a fresh data: 1144108930 101027544 1458777923 1115438165 74243042 <br \/>  BoozdedZomby has got a fresh data: 143542612 1131570933 <br \/>  BoozdedZomby has got a fresh data: 893351816 563613512 704877633 <br \/>  BoozdedZomby has got a fresh data: 1551901393 1399125485 1899894091 937186357 590357944 357571490 <br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  BoozdedZomby has got a fresh data: 1927702196 130060903 1083454666 2118797801 2035308228 824938981 <br \/>  BoozdedZomby has got a fresh data: 2020739063 1635339425 34075629 <br \/>  BoozdedZomby has got a fresh data: 2146319451 500782188 1269406752 884936716 892053144 <br \/>  BoozdedZomby has got a fresh data: 330111137 1723153177 1070477904 <br \/>  BoozdedZomby has got a fresh data: 343098142 280090412 589673557 889688008 2014119113 388471006   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">BoozdedZomby::Zomby::runOnce<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;BoozdedZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()]() {         while (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_semaphore &amp;&amp; shis-&gt;_listener) {             auto handler = [&shis;](auto errorCode) {                 if (shis &amp;&amp; shis.use_count() &gt; 1 &amp;&amp; shis-&gt;_listener &amp;&amp; errorCode == boozd::azzio::io_context::error_code::no_error) {                     std::ostringstream buf;                     buf &lt;&lt; &quot;BoozdedZomby has got a fresh data: &quot;;                     for (auto const &elem; : shis-&gt;_buffer)                         buf &lt;&lt; elem &lt;&lt; ' ';                     buf &lt;&lt; std::endl;                      shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));                 }             };             shis-&gt;_buffer.clear();             shis-&gt;_context.async_read(shis-&gt;_stream, shis-&gt;_buffer, handler);             shis-&gt;_context.run();         }     }); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>BoozdedZomby has got a fresh data: 1144108930 101027544 1458777923 1115438165 74243042 <br \/>  BoozdedZomby has got a fresh data: 143542612 1131570933 <br \/>  BoozdedZomby has got a fresh data: 893351816 563613512 704877633 <br \/>  BoozdedZomby has got a fresh data: 1551901393 1399125485 1899894091 937186357 590357944 357571490 <br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N12BoozdedZomby5ZombyE::~Zomby<br \/>  N5boozd5azzio10io_contextE::~io_context<br \/>  N5boozd5azzio13random_streamE::~random_stream<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0442 \u0442\u0443\u0442 \u0443\u0436\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0432 weak-\u0441\u043f\u043e\u0441\u043e\u0431\u0435: \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 listener, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438.<br \/>  \u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u0443\u044e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c: \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043f\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0437\u043e\u043c\u0431\u0438 (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u2014 \u0441\u0435\u0439\u0447\u0430\u0441 shis \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u0430 \u043d\u0435 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e). \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<br \/>  \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 \u043f\u043e use_count-\u0441\u043f\u043e\u0441\u043e\u0431\u0443<\/h3>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 use_count \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u0430 shared_from_this \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0440\u0438\u0441\u043a \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 weak-\u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0438\u0441\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 listener \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u043e\u043c\u0431\u0438 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<p>  \u0421\u043f\u043e\u0441\u043e\u0431\u044b use_count \u0438 weak \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043f\u0440\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c\u0438 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c:<br \/>   \u2014 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043e\u043c\u0431\u0438 \u043f\u0440\u043e\u043a\u0441\u0438-listener&#8217;a, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u044b\u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c listener&#8217;\u043e\u043c (\u043d\u043e \u043d\u0435 \u043e\u0431\u043e\u043b\u044c\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u2014 \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u043d\u0438 \u0438\u0437\u044f\u0449\u043d\u044b\u043c; \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0432\u0435\u0442\u043a\u0430 fixes\/weak_with_ProxyListener);<br \/>   \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0442\u0438\u043f\u0430 Qt Signals &amp; Slots (\u043e\u0434\u043d\u0430\u043a\u043e \u0442\u0443\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043b\u043b\u044e\u0437\u0438\u044e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438);<br \/>   \u2014 \u043e\u0442\u043a\u0430\u0437 \u043e\u0442 event-driven \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u043f\u043e\u043b\u043b\u0438\u043d\u0433\u0430 \u2014 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u0442\u0438\u0432\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0443\u0440\u043e\u0432\u043d\u044e, \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043d\u0438\u0436\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e. <\/p>\n<h2>\u0421\u043f\u043e\u0441\u043e\u0431 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u0438\u043b\u0438 this<\/h2>\n<p>  <b>\u0418\u0434\u0435\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/b> \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043e\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 std::shared_from_this. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0433\u0440\u044f\u0437\u043d\u044b\u0445 \u0442\u0440\u044e\u043a\u043e\u0432 \u0441 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>  \u041b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 this. \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0432\u043c\u0435\u0441\u0442\u043e std::thread::detach() \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f std::thread::join().<br \/>  \u0417\u043e\u043c\u0431\u0438 \u0440\u0430\u0441\u0442\u0432\u043e\u0440\u044f\u0435\u0442\u0441\u044f.<br \/>  \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0441\u0435\u0432\u0434\u043e-\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441: \u0432\u0441\u0435 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438, \u043a\u0440\u043e\u043c\u0435 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0423\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u2014 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u0438\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438 \u0434\u0430\u0436\u0435 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0441\u0435\u043a\u0443\u043d\u0434, \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u0442\u0435\u0440\u0438 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u0442.\u043f.).<\/p>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;memory&gt; #include &lt;atomic&gt; #include &lt;thread&gt;  #include &quot;Common\/Manager.h&quot;  namespace Common { class Listener; } \/\/ namespace Common  namespace SimpleZomby { class Zomby final : public Common::Manager, public std::enable_shared_from_this&lt;Zomby&gt; { public:     static std::shared_ptr&lt;Zomby&gt; create();      ~Zomby() override;      void runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) override;  private:     Zomby();      using Semaphore = std::atomic&lt;bool&gt;;      std::shared_ptr&lt;Common::Listener&gt; _listener;     Semaphore _semaphore = false;     std::thread _thread; }; } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;sstream&gt;  #include &quot;SimpleZomby.h&quot; #include &quot;Common\/Listener.h&quot;  namespace SimpleZomby { std::shared_ptr&lt;Zomby&gt; Zomby::create() {     return std::shared_ptr&lt;Zomby&gt;(new Zomby()); }  Zomby::Zomby() = default;  Zomby::~Zomby() {     _semaphore = false;      if (_thread.joinable()) {         _thread.detach();     }      if (_listener) {         std::ostringstream buf;         buf &lt;&lt; typeid(*this).name() &lt;&lt; &quot;::&quot; &lt;&lt; __func__ &lt;&lt; std::endl;         _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));     } }  void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         while (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;memory&gt; #include &lt;atomic&gt; #include &lt;thread&gt;  #include &quot;Common\/Manager.h&quot;  namespace Common { class Listener; } \/\/ namespace Common  namespace SimpleZomby { class Zomby final : public Common::Manager { public:     static std::shared_ptr&lt;Zomby&gt; create();      ~Zomby() override;      void runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) override;  private:     Zomby();      using Semaphore = std::atomic&lt;bool&gt;;      std::shared_ptr&lt;Common::Listener&gt; _listener;     Semaphore _semaphore = false;     std::thread _thread; }; } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;sstream&gt;  #include &quot;SimpleZomby.h&quot; #include &quot;Common\/Listener.h&quot;  namespace SimpleZomby { std::shared_ptr&lt;Zomby&gt; Zomby::create() {     return std::shared_ptr&lt;Zomby&gt;(new Zomby()); }  Zomby::Zomby() = default;  Zomby::~Zomby() {     _semaphore = false;      if (_thread.joinable()) {         _thread.join();     }      if (_listener) {         std::ostringstream buf;         buf &lt;&lt; typeid(*this).name() &lt;&lt; &quot;::&quot; &lt;&lt; __func__ &lt;&lt; std::endl;         _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));     } }  void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([this](){         while (_listener &amp;&amp; _semaphore) {             _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0442\u043c\u0435\u0442\u0438\u043c:<br \/>   \u2014 \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0437\u043e\u043c\u0431\u0438 (\u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0443\u0436\u0435 \u0438 \u043d\u0435 \u0437\u043e\u043c\u0431\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435) \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d <b>\u0434\u043e<\/b> \u0432\u044b\u0432\u043e\u0434\u0430 \u00abZomby was killed\u00bb;<br \/>   \u2014 \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0441\u044b\u0433\u0440\u0430\u043b \u0442\u0443 \u0440\u043e\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0435\u043c\u0443 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e, \u0445\u043e\u0442\u044f \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 _listener;<br \/>   \u2014 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 std::shared_ptr \u0441\u0442\u0430\u043b\u043e \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e create() \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0437\u0434\u043d\u0438\u0442\u044c \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0432\u044b\u043d\u043e\u0441\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0432 public-\u0441\u0435\u043a\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430;<br \/>   \u2014 \u0437\u0430\u0445\u0432\u0430\u0442 this \u0432 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u2014 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 Common::Manager \u0437\u0430\u043f\u0440\u0435\u0442 copy- \u0438 move-\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u0430\u0436\u0435\u043d.<\/p>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 SteppingZomby \u0438 BoozdedZomby \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0432\u0435\u0442\u043a\u0435 fixes\/this \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 \u043f\u043e this-\u0441\u043f\u043e\u0441\u043e\u0431\u0443<\/h3>\n<p>  \u0421\u043f\u043e\u0441\u043e\u0431 \u0445\u043e\u0440\u043e\u0448 \u0432\u0441\u0435\u043c, \u043a\u0440\u043e\u043c\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 GUI-\u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u043a\u0443\u043d\u0434 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u0448\u0438\u043c. \u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043f\u0440\u0438\u0433\u043e\u0434\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<h2>\u0421\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u0439, \u0438\u043b\u0438 semaphore_done_right<\/h2>\n<p>  \u0412\u043e \u0432\u0441\u0435\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043a\u0430\u043a \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<br \/>  \u0414\u0430, \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0443\u0434\u043e\u0431\u043d\u043e.<br \/>  \u041d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0431\u0443\u043a\u0435\u0442\u0443 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>  <b>\u0418\u0434\u0435\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/b> \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u043c.<br \/>  \u041e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0430:<br \/>   \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u0430;<br \/>   \u2014 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u0432 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435.<br \/>  \u041e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0442\u043e\u043a\u0430:<br \/>   \u2014 \u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044e\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430.<br \/>  \u041d\u0438\u043a\u0430\u043a\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c (\u043a\u0440\u043e\u043c\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430), \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043e\u0442 \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0432\u044b\u0448\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430). \u041d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043b\u044f\u043c\u0431\u0434\u0443 \u2014 \u043d\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0441\u044b\u0440\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043d\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0443\u043c\u043d\u043e\u0433\u043e.<br \/>  \u0414\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0448\u0435\u0439 \u0432 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 weak \u0438 use_count, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430. \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u0435\u043d\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430, \u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u2014 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 listener.<br \/>  \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 std::thread::detach(), \u043d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 (\u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043f\u043e\u0437\u0434\u043d\u0435\u0435).<\/p>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;memory&gt; #include &lt;atomic&gt; #include &lt;thread&gt;  #include &quot;Common\/Manager.h&quot;  namespace Common { class Listener; } \/\/ namespace Common  namespace SimpleZomby { class Zomby final : public Common::Manager, public std::enable_shared_from_this&lt;Zomby&gt; { public:     static std::shared_ptr&lt;Zomby&gt; create();      ~Zomby() override;      void runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) override;  private:     Zomby();      using Semaphore = std::atomic&lt;bool&gt;;      std::shared_ptr&lt;Common::Listener&gt; _listener;     Semaphore _semaphore = false;     std::thread _thread; }; } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;sstream&gt;  #include &quot;SimpleZomby.h&quot; #include &quot;Common\/Listener.h&quot;  namespace SimpleZomby { std::shared_ptr&lt;Zomby&gt; Zomby::create() {     return std::shared_ptr&lt;Zomby&gt;(new Zomby()); }  Zomby::Zomby() = default;  Zomby::~Zomby() {     _semaphore = false;      if (_thread.joinable()) {         _thread.detach();     }      if (_listener) {         std::ostringstream buf;         buf &lt;&lt; typeid(*this).name() &lt;&lt; &quot;::&quot; &lt;&lt; __func__ &lt;&lt; std::endl;         _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));     } }  void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     _semaphore = true;      _thread = std::thread([shis = shared_from_this()](){         while (shis &amp;&amp; shis-&gt;_listener &amp;&amp; shis-&gt;_semaphore) {             shis-&gt;_listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;memory&gt; #include &lt;atomic&gt; #include &lt;thread&gt;  #include &quot;Common\/Manager.h&quot;  namespace Common { class Listener; } \/\/ namespace Common  namespace SimpleZomby { class Zomby final : public Common::Manager { public:     static std::shared_ptr&lt;Zomby&gt; create();      ~Zomby() override;      void runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) override;  private:     Zomby();      using Semaphore = std::pair&lt;std::mutex, bool&gt;;      std::shared_ptr&lt;Common::Listener&gt; _listener;     std::shared_ptr&lt;Semaphore&gt; _semaphore;     std::thread _thread; }; } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;sstream&gt;  #include &quot;SimpleZomby.h&quot; #include &quot;Common\/Listener.h&quot;  namespace SimpleZomby { std::shared_ptr&lt;Zomby&gt; Zomby::create() {     return std::shared_ptr&lt;Zomby&gt;(new Zomby()); }  Zomby::Zomby() = default;  Zomby::~Zomby() {     if (_semaphore) {         if (std::this_thread::get_id() != _thread.get_id()) {             auto guard = std::lock_guard(_semaphore-&gt;first);             _semaphore-&gt;second = false;         } else {             _semaphore-&gt;second = false;         }     }      if (_thread.joinable()) {         _thread.detach();     }      if (_listener) {         std::ostringstream buf;         buf &lt;&lt; typeid(*this).name() &lt;&lt; &quot;::&quot; &lt;&lt; __func__ &lt;&lt; std::endl;         _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));     } }  void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     \/\/ two separate lines needed because of absence of std::mutex move c-tor     _semaphore = std::make_shared&lt;Semaphore&gt;();     _semaphore-&gt;second = true;      _thread = std::thread([listener, semaphore = _semaphore](){         while (listener &amp;&amp; semaphore) {             {                 auto guard = std::lock_guard(semaphore-&gt;first);                 if (!semaphore-&gt;second) {                     break;                 }                 listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             }             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0434\u043b\u044f SteppingZomby \u0438 BoozdedZomby \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b (\u0441\u043c. \u0432\u0435\u0442\u043a\u0443 fixes\/semaphore_done_right) \u2014 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b, \u0447\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 BoozdedZomby \u0441\u043e\u0432\u043f\u0430\u043b\u043e \u0441 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430 SimpleZomby, \u0430 \u0432 SteppingZomby \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438\u0448\u044c \u0434\u043e\u043f\u043e\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<br \/>   \u2014 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 \u2014 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044f \u0437\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u0437\u0430\u0449\u0438\u0449\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443;<br \/>   \u2014 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438 \u2014 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 listener \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430;<br \/>   \u2014 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 deadlock&#8217;\u0430 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0432\u043f\u043e\u043b\u043d\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439);<br \/>   \u2014 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 std::shared_ptr \u0441\u0442\u0430\u043b\u043e \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e create() \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0437\u0434\u043d\u0438\u0442\u044c \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0432\u044b\u043d\u043e\u0441\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0432 public-\u0441\u0435\u043a\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430;<br \/>   \u2014 \u0437\u0430\u043f\u0440\u0435\u0442 copy- \u0438 move-\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 Common::Manager, \u0441\u0442\u0430\u043b \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c;<br \/>   \u2014 listener \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u043e\u043d \u043d\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f;<br \/>   \u2014 \u043a\u043b\u0430\u0441\u0441 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0447\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f;<br \/>   \u2014 \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432 detached-\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0443\u043d\u043a\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u043c \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c:<br \/>   \u2014 \u043c\u0430\u0441\u043a\u0438\u0440\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435;<br \/>   \u2014 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0436\u0438\u0442\u044c \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u0442\u043e\u0433\u0434\u0430 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0437\u0430\u0447\u0438\u0449\u0435\u043d \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0441\u0431\u043e\u044e \u0434\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u0421\u043f\u043e\u0441\u043e\u0431 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439, \u0438\u043b\u0438 semaphore_done_right_with_ThreadJoiner<\/h2>\n<p>  \u0415\u0441\u043b\u0438 detach() \u043f\u043e\u0442\u043e\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c (<s>\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430<\/s>).<\/p>\n<p>  <b>\u0418\u0434\u0435\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/b><br \/>   \u2014 \u043d\u0443\u0436\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (ThreadJoiner), \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430\u044f \u0432\u0437\u044f\u0442\u044c \u043d\u0430 \u0441\u0435\u0431\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0432\u0448\u0438\u0439 \u043f\u043e\u0442\u043e\u043a (\u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u2014 ThreadSanitizer, \u043d\u043e \u043e\u043d\u043e \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u043e);<br \/>   \u2014 ThreadJoiner \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u043a\u0438 std::thread::join() \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u0440\u0438\u043d\u044f\u043b;<br \/>   \u2014 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 ThreadJoiner \u0431\u0443\u0434\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043a\u0438, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u0440\u0438\u043d\u044f\u043b.<\/p>\n<p>  \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ThreadJoiner.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;thread&gt;  namespace Common { class ThreadJoiner { public:     ThreadJoiner() = default;     ThreadJoiner(const ThreadJoiner&amp;) = delete;     ThreadJoiner(ThreadJoiner&amp;&amp;) = delete;     ThreadJoiner&amp; operator=(const ThreadJoiner&amp;) = delete;     ThreadJoiner&amp; operator=(ThreadJoiner&amp;&amp;) = delete;      virtual ~ThreadJoiner() = default;      virtual void join(std::thread&amp;&amp;) = 0; }; } \/\/ namespace Common <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ThreadJoinerAsync.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;thread&gt; #include &lt;queue&gt; #include &lt;mutex&gt; #include &lt;optional&gt; #include &lt;condition_variable&gt;  #include &quot;Common\/ThreadJoiner.h&quot;  namespace Common { class ThreadJoinerAsync final : public ThreadJoiner { public:     ThreadJoinerAsync();     ThreadJoinerAsync(const ThreadJoinerAsync&amp;) = delete;     ThreadJoinerAsync(ThreadJoinerAsync&amp;&amp;) = delete;     ThreadJoinerAsync&amp; operator=(const ThreadJoinerAsync&amp;) = delete;     ThreadJoinerAsync&amp; operator=(ThreadJoinerAsync&amp;&amp;) = delete;      ~ThreadJoinerAsync() override;      void join(std::thread&amp;&amp;) override;  private:     using Data = std::queue&lt;std::thread&gt;;     using Semaphore = std::atomic&lt;bool&gt;;      std::mutex _mutex;     Data _data;     Semaphore _semaphore;     std::condition_variable _cv;     std::thread _thread;      void threadFn(); }; } \/\/ namespace Common <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ThreadJoinerAsync.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &quot;ThreadJoinerAsync.h&quot;  namespace Common { ThreadJoinerAsync::ThreadJoinerAsync()     : _semaphore(true)     , _thread(&amp;ThreadJoinerAsync::threadFn, this) { }  ThreadJoinerAsync::~ThreadJoinerAsync() {     _semaphore = false;     _cv.notify_one();      if (_thread.joinable()) {         _thread.join();     } }  void ThreadJoinerAsync::join(std::thread&amp;&amp; thread) {     {         auto lock = std::lock_guard(_mutex);         _data.push(std::move(thread));     }      _cv.notify_one(); }  void ThreadJoinerAsync::threadFn() {     while (true) {         auto lock = std::unique_lock(_mutex);         _cv.wait(lock, [this](){ return !_semaphore || !_data.empty(); });          if (!_semaphore &amp;&amp; _data.empty()) {             return;         }          auto threadToJoin = std::move(_data.front());         _data.pop();          lock.unlock();          if (threadToJoin.joinable()) {             threadToJoin.join();         }     } } } \/\/ namespace Common <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 ThreadJoiner \u0432 SimpleZomby:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  #include &lt;memory&gt; #include &lt;atomic&gt; #include &lt;thread&gt;  #include &quot;Common\/Manager.h&quot;  namespace Common { class Listener; class ThreadJoiner; } \/\/ namespace Common  namespace SimpleZomby { class Zomby final : public Common::Manager { public:     Zomby(std::shared_ptr&lt;Common::ThreadJoiner&gt;);      ~Zomby() override;      void runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) override;  private:      using Semaphore = std::pair&lt;std::mutex, bool&gt;;      std::shared_ptr&lt;Common::Listener&gt; _listener;     std::shared_ptr&lt;Semaphore&gt; _semaphore;     std::thread _thread;     const std::shared_ptr&lt;Common::ThreadJoiner&gt; _joiner; }; } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SimpleZomby.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;sstream&gt;  #include &quot;SimpleZomby.h&quot; #include &quot;Common\/Listener.h&quot; #include &quot;Common\/ThreadJoiner.h&quot;  namespace SimpleZomby { Zomby::Zomby(std::shared_ptr&lt;Common::ThreadJoiner&gt; joiner)     : _joiner(joiner) {     if (!_joiner) {         throw std::runtime_error(&quot;An empty joiner in SimpleZomby::Zomby::Zomby&quot;);     } }  Zomby::~Zomby() {     if (_semaphore) {         if (std::this_thread::get_id() != _thread.get_id()) {             auto guard = std::lock_guard(_semaphore-&gt;first);             _semaphore-&gt;second = false;         } else {             _semaphore-&gt;second = false;         }     }      if (_thread.joinable()) {         _joiner-&gt;join(std::move(_thread));     }      if (_listener) {         std::ostringstream buf;         buf &lt;&lt; typeid(*this).name() &lt;&lt; &quot;::&quot; &lt;&lt; __func__ &lt;&lt; std::endl;         _listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));     } }  void Zomby::runOnce(std::shared_ptr&lt;Common::Listener&gt; listener) {     if (_semaphore) {         throw std::runtime_error(&quot;SimpleZomby::Zomby::runOnce() called twice&quot;);     }      _listener = listener;     \/\/ two separate lines needed because of absence of std::mutex move c-tor     _semaphore = std::make_shared&lt;Semaphore&gt;();     _semaphore-&gt;second = true;      _thread = std::thread([listener, semaphore = _semaphore](){         while (listener &amp;&amp; semaphore) {             {                 auto guard = std::lock_guard(semaphore-&gt;first);                 if (!semaphore-&gt;second) {                     break;                 }                 listener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(&quot;SimpleZomby is alive!\\n&quot;));             }             std::this_thread::sleep_for(std::chrono::seconds(1));         }     }); } } \/\/ namespace SimpleZomby <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.cpp<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;chrono&gt; #include &lt;thread&gt; #include &lt;sstream&gt;  #include &quot;Common\/Impl\/WriteToConsoleListener.h&quot; #include &quot;Common\/Impl\/ThreadJoinerAsync.h&quot; #include &quot;SimpleZomby\/SimpleZomby.h&quot;  int main() {     auto writeToConsoleListener = Common::WriteToConsoleListener::instance();     auto joiner = std::make_shared&lt;Common::ThreadJoinerAsync&gt;();      {         auto simpleZomby = SimpleZomby::Zomby(joiner);         simpleZomby.runOnce(writeToConsoleListener);          std::this_thread::sleep_for(std::chrono::milliseconds(4500));     } \/\/ Zomby should be killed here      {         std::ostringstream buf;         buf &lt;&lt; &quot;============================================================\\n&quot;             &lt;&lt; &quot;|                      Zomby was killed                    |\\n&quot;             &lt;&lt; &quot;============================================================\\n&quot;;         if (writeToConsoleListener) {             writeToConsoleListener-&gt;processData(std::make_shared&lt;Common::Listener::Data&gt;(buf.str()));         }     }      std::this_thread::sleep_for(std::chrono::milliseconds(5000));      return 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p>SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  SimpleZomby is alive!<br \/>  N11SimpleZomby5ZombyE::~Zomby<br \/>  ============================================================<br \/>  | Zomby was killed |<br \/>  ============================================================<br \/>  N6Common22WriteToConsoleListenerE::~WriteToConsoleListener  <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  <b>\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435:<\/b> \u043a\u043e\u0434 ThreadJoiner \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e; \u0437\u0430\u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u0432\u0442\u0430\u0449\u0438\u0442\u044c \u0435\u0433\u043e \u0432 production \u2014 \u044f \u043d\u0435 \u0432\u0438\u043d\u043e\u0432\u0430\u0442.<\/p>\n<p>  \u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<br \/>   \u2014 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043b\u043e\u0436\u0435\u043d\u0430 \u043d\u0430 ThreadJoiner;<br \/>   \u2014 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0435\u0439 \u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442 \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438;<br \/>   \u2014 ThreadJoiner \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0449\u0438\u043c\u0438 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u0435\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c\u0443 \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 SteppingZomby \u0438 BoozdedZomby \u2014 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b (\u0441\u043c. \u0432\u0435\u0442\u043a\u0443 fixes\/semaphore_done_right_with_ThreadJoiner).<\/p>\n<h2>\u041f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e\u0431 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 boost<\/h2>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0434\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 boost:<br \/>  <a href=\"https:\/\/www.boost.org\/doc\/libs\/master\/libs\/beast\/example\/http\/client\/async\/http_client_async.cpp\" rel=\"nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/a><br \/>  <a href=\"https:\/\/www.boost.org\/doc\/libs\/develop\/libs\/beast\/example\/websocket\/client\/async\/websocket_client_async.cpp\" rel=\"nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440 Websocket-\u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/a><br \/>  \u0412\u044b\u0437\u043e\u0432 ioc.run() \u0432 main() \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:<br \/>   \u2014 \u0443\u0441\u043f\u0435\u0448\u043d\u0430\u044f \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0441\u0435\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438;<br \/>   \u2014 \u043e\u0448\u0438\u0431\u043a\u0430.<br \/>  \u0414\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 session <b>\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435<\/b> \u043d\u0435\u0432\u043e\u0437\u043e\u043c\u043e\u0436\u043d\u043e. \u042d\u0442\u043e \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u044f\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 session. \u0421\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0435\u0433\u043e this-\u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 shared_from_this \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u0441\u044b\u0440\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f this.<\/p>\n<p>  <b>\u041e\u0442\u043a\u0443\u0434\u0430 \u0436\u0435 \u0442\u043e\u0433\u0434\u0430 \u0432\u0437\u044f\u043b\u0441\u044f shared_from_this?<\/b><br \/>  \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0451\u043c \u0435\u0433\u043e \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f. \u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e (\u0447\u0438\u0442\u0430\u0439 \u00ab\u043a \u043a\u0440\u044d\u0448\u0430\u043c\u00bb). \u041a\u0440\u044d\u0448\u0438 \u0440\u0430\u0437\u043c\u0435\u043d\u044f\u043b\u0438 \u043d\u0430 \u0437\u043e\u043c\u0431\u0438, \u0430 \u0437\u043e\u043c\u0431\u0438 \u043f\u043e\u0434\u0430\u0440\u0438\u043b\u0438 \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0435\u0440\u0430\u043c.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b. \u041e\u043d\u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, <b>\u043a\u0430\u043a\u0438\u0435<\/b> \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c:<br \/>   \u2014 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 single responsibility \u2014 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 \u0431\u044b\u043b\u0438 \u0432\u043e\u0437\u043b\u043e\u0436\u0435\u043d\u044b \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438, \u0442\u0430\u043a \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430;<br \/>   \u2014 \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442 \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a \u0432\u044b\u0448\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0439 \u2014 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0443\u0436\u0434\u0430\u043b\u0441\u044f \u0432 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438;<br \/>   \u2014 \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0438 std::enable_shared_from_this.<\/p>\n<p>  \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <b>\u0431\u0435\u0437<\/b> \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f std::enable_shared_from_this.<\/p>\n<p>  \u0427\u0435\u0433\u043e \u0438 \u0412\u0430\u043c \u0436\u0435\u043b\u0430\u044e.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/478190\/\"> https:\/\/habr.com\/ru\/post\/478190\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/478190\/\">\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u043e\u0440 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438: <a href=\"https:\/\/habr.com\/ru\/post\/471326\/\">\u0421\u043a\u0430\u0437 \u043e\u0431 \u043e\u043f\u0430\u0441\u043d\u043e\u043c std::enable_shared_from_this, \u0438\u043b\u0438 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d \u00ab\u0417\u043e\u043c\u0431\u0438\u00bb<\/a>.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297301","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297301"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297301\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}