{"id":321062,"date":"2021-04-07T15:01:42","date_gmt":"2021-04-07T15:01:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321062"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321062","title":{"rendered":"\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u041f\u041e"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430 \u0444\u043e\u043d\u0435 \u0433\u0440\u0435\u043c\u044f\u0449\u0438\u0445 \u0437\u0434\u0435\u0441\u044c \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0439 \u043f\u0440\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0438 \u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u042f\u043d\u0434\u0435\u043a\u0441, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u043c\u043e\u0439 \u043f\u0440\u0438\u044f\u0442\u0435\u043b\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u043d\u0435-\u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439) \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0437 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u043c\u043d\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u043e\u043d\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u0434\u0430\u0447\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c (\u043e\u043d\u0438 \u043d\u0430\u0448\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0435\u043d\u0438\u044f, \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0441\u0442\u0430\u0440\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>\u041a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0443, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0435\u043c\u0443 \u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u0438  \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0435\u043a, \u043d\u0435 \u0433\u043e\u043d\u044f\u043b\u0438 \u043f\u043e \u0434\u0435\u0431\u0440\u044f\u043c \u044f\u0437\u044b\u043a\u0430, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u0432\u0430\u043b\u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e \u043a\u043e\u0434. \u041a\u043e\u0434 \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043c\u0451\u0440\u0436\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0437\u0435\u043b\u0435\u043d\u044b\u0439 \u0434\u0436\u0443\u043d\u0438\u043e\u0440. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432\u043e\u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0418\u0437\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. (\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u043d\u043e \u0432\u043e\u0442 \u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u0435\u0434\u0430, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 code-review, \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043f\u043b\u043e\u0445\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0434 \u043d\u0430 C++, \u0445\u043e\u0442\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u0436\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041a\u043e\u0434 \u0431\u044b\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">class SomeServiceClient { public:   SomeServiceClient();   virtual ~SomeServiceClient();   bool CallAsync(const std::string &amp;uri, const std::string &amp;param,                  const misc::BusServiceClient::ResponseCB &amp;callback);   bool CallSync(const std::string &amp;uri, const std::string &amp;param,                 const misc::BusServiceClient::ResponseCB &amp;callback);  private:   misc::BusServiceClient ss_client_;    static const int kSleepMs = 100;   static const int kSleepCountMax = 50; };  class SpecificUrlFetcher : public UrlFetcher { public:   SpecificUrlFetcher();   virtual ~SpecificUrlFetcher();    SomeData FetchData(const URL &amp;url, const UrlFetcher::ResponseCB &amp;callback);  private:   bool SsResponse_returnValue{false};   char SsResponse_url[1024];    void SsResponseCallback(const std::string &amp;response);    SomeServiceClient *ss_client_; };  \/\/ ...  static const char ss_getlocalfile_uri[] = \"bus:\/\/url_replace_service\";  namespace net {  pthread_mutex_t g_url_change_callback_lock = PTHREAD_MUTEX_INITIALIZER;  SomeBusServiceClient::SomeBusServiceClient()     : ss_client_(misc::BusServiceClient::PrivateBus) {}  SomeBusServiceClient::~SomeBusServiceClient() {}  bool SomeBusServiceClient::CallAsync(     const std::string &amp;uri, const std::string &amp;param,     const misc::BusServiceClient::ResponseCB &amp;callback) {   bool bRet;   bRet = ss_client_.callASync(uri, param, callback);   return bRet; }  bool SomeBusServiceClient::CallSync(     const std::string &amp;uri, const std::string &amp;param,     const misc::BusServiceClient::ResponseCB &amp;callback) {   boold bRet bRet = false;   int counter;    pthread_mutex_lock(&amp;g_url_change_callback_lock);   ss_client_.callASync(uri, param, callback);    counter = 0;   for (;;) {     int r = pthread_mutex_trylock(&amp;g_url_change_callback_lock);     if (r == 0) {       bRet = true;       pthread_mutex_unlock(&amp;g_url_change_callback_lock);     } else if (r == EBUSY) {       usleep(kSleepMs);       counter++;       if (counter &gt;= kSleepCountMax) {         pthread_mutex_unlock(&amp;g_url_change_callback_lock);         break;       } else         continue;     }     break;   }   return bRet; }  \/**************************************************************************\/  SpecificUrlFetcher::SpecificUrlFetcher() {} SpecificUrlFetcher::~SpecificUrlFetcher() {}  void SpecificUrlFetcher::SsResponseCallback(const std::string &amp;response) {   std::unique_ptr&lt;lib::Value&gt; value(lib::JSONReader::Read(response));   if (!value.get() || !value-&gt;is_dict()) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }    lib::DictionaryValue *response_data =       static_cast&lt;lib::DictionaryValue *&gt;(value.get());   bool returnValue;   if (!response_data-&gt;GetBoolean(\"returnValue\", &amp;returnValue) || !returnValue) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }    std::string url;   if (!response_data-&gt;GetString(\"url\", &amp;url)) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }   SsResponse_returnValue = true;    size_t array_sz = arraysize(SsResponse_url);   strncpy(SsResponse_url, url.c_str(), array_sz);   SsResponse_url[array_sz - 1] = 0;    pthread_mutex_unlock(&amp;g_url_change_callback_lock); }  SomeData SpecificUrlFetcher::FetchData(const URL &amp;url,                                        const UrlFetcher::ResponseCB &amp;callback) {   lib::DictionaryValue dictionary;   std::string ss_request_payload;    misc::BusServiceClient::ResponseCB response_cb =       lib::Bind(&amp;SpecificUrlFetcher::SsResponseCallback, this);    SomeBusServiceClient *ss_client_ = new SomeBusServiceClient();    dictionary.SetString(\"url\", url.to_string());   lib::JSONWriter::Write(dictionary, &amp;ss_request_payload);    SsResponse_returnValue = false;   SsResponse_url[0] = 0x00;    ss_client_-&gt;CallSync(ss_getlocalfile_uri, ss_request_payload, response_cb);   URL new_url;   if (SsResponse_returnValue) {     new_url = URL::from_string(SsResponse_url);   }    delete ss_client_;   return UrlFetcher::FetchData(new_url, callback); }  } \/\/ namespace net<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c, \u043d\u0430\u0436\u0438\u043c\u0430\u0439\u0442\u0435 \u043d\u0430 \u043d\u0435\u0433\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e, \u043f\u0443\u0442\u0438 \u043d\u0430\u0437\u0430\u0434 \u0443\u0436\u0435 \u043d\u0435\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u0430\u043a, \u043e\u0442\u0432\u0435\u0442\u044b.<\/summary>\n<div class=\"spoiler__content\">\n<ol>\n<li>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043b\u0430\u0441\u0441 UrlFetcher, \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 &#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e URL&#8217;\u0443. \u0423\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0448\u0438\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0439 URL, \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0435\u043a\u0438\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 URL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u042d\u0442\u0430\u043a\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d Decorator.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u043c\u0435\u043b\u043e\u0447\u0430\u043c:<\/p>\n<p>1. ss_getlocalfile_uri &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u0417\u0430\u0447\u0435\u043c? \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0435\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>2. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u0449\u0435\u0439 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0435 \u0435\u0439 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c.<\/p>\n<p>3. \u0421\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 SsResponse_returnValue <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e-\u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f pthread-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438 \u0442\u043e\u043c \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 std::thread, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>5. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0421\u0438-\u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 strncpy(); \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::string \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>6. ss_client_ \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u044b\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::unique_ptr.<\/p>\n<p>7. \u0412\u043c\u0435\u0441\u0442\u043e usleep() \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::this_thread::sleep()<\/p>\n<p>\u0415\u0449\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>8. \u0412 \u0446\u0438\u043a\u043b\u0435 \u0432 SomeBusServiceClient::CallSync \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0431\u044d\u043a \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043f\u0440\u0438\u0434\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0437\u0430 kSleepMs \u0434\u043e kSleepCountMax, \u0442\u043e \u043c\u044b \u043e\u0442\u043a\u0438\u043d\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443. \u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0449\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>9. \u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 message bus \u0438 \u0436\u0434\u0435\u043c. \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u043d\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 message bus, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a kSleepCountMax*kSleepMs, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0430\u043c \u0441\u0442\u0430\u043b \u043d\u0435 \u043d\u0443\u0436\u0435\u043d (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e callASync \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c id \u0437\u0430\u043f\u0440\u043e\u0441\u0430?). \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u0436\u0434\u0435\u043c, \u0430 \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u0449\u0438\u0439 URL, \u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u044b\u0439 \u0431\u0430\u0440\u0434\u0430\u043a.<\/p>\n<p>9. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 FetchData \u043d\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443, new_url \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0439.<\/p>\n<p>10. \u041c\u0435\u0442\u043e\u0434 FetchUrl, \u0441\u0443\u0434\u044f \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439. \u0412 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0436\u0435 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 &#8212; WTF? \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e? \u0418 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e \u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435?<\/p>\n<p>11. \u0421\u0443\u0434\u044f \u043f\u043e \u043b\u043e\u0433\u0438\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u044b (\u0432\u044b\u0437\u043e\u0432 FetchUrl \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0435\u0434), SsResponseCallback \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0442\u0440\u0435\u0434\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0442 \u043d\u0435 \u0432 \u0442\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0433\u0434\u0435 \u043c\u044b \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438. \u0414\u043b\u044f pthread \u044d\u0442\u043e \u044f\u0432\u043d\u044b\u0439 undefined behavior.<\/p>\n<p>12. \u0426\u0435\u043d\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043e\u0442 <a class=\"mention\" href=\"\/users\/snizovtsev\">@snizovtsev<\/a>: &#171;&#8230;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u043b\u044c\u0437\u044f. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 2 \u0440\u0430\u0437\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f unlock. \u0422.\u0435. \u043a\u043e\u0434 \u043d\u0435\u0432\u0435\u0440\u0435\u043d \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435  \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0451 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430 condition variable&#187;<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u043e\u0442 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430\u043c\u0438 C++ \u0438 \u0445\u043e\u0440\u043e\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438, \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0434\u043e\u0442\u043e\u0448\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e \u0438 \u0443\u043c\u0435\u043d\u0438\u0438 &#171;\u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c&#187; \u043a\u043e\u0434 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435. \u041d\u0443 \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0430 \u043f\u043e \u0434\u0443\u0448\u0430\u043c.<\/p>\n<\/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\/551202\/\"> https:\/\/habr.com\/ru\/post\/551202\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430 \u0444\u043e\u043d\u0435 \u0433\u0440\u0435\u043c\u044f\u0449\u0438\u0445 \u0437\u0434\u0435\u0441\u044c \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0439 \u043f\u0440\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0438 \u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u042f\u043d\u0434\u0435\u043a\u0441, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u043c\u043e\u0439 \u043f\u0440\u0438\u044f\u0442\u0435\u043b\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u043d\u0435-\u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439) \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0437 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u043c\u043d\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u043e\u043d\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u0434\u0430\u0447\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c (\u043e\u043d\u0438 \u043d\u0430\u0448\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0435\u043d\u0438\u044f, \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0441\u0442\u0430\u0440\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>\u041a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0443, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0435\u043c\u0443 \u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u0438  \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0435\u043a, \u043d\u0435 \u0433\u043e\u043d\u044f\u043b\u0438 \u043f\u043e \u0434\u0435\u0431\u0440\u044f\u043c \u044f\u0437\u044b\u043a\u0430, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u0432\u0430\u043b\u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e \u043a\u043e\u0434. \u041a\u043e\u0434 \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043c\u0451\u0440\u0436\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0437\u0435\u043b\u0435\u043d\u044b\u0439 \u0434\u0436\u0443\u043d\u0438\u043e\u0440. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432\u043e\u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0418\u0437\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. (\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u043d\u043e \u0432\u043e\u0442 \u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u0435\u0434\u0430, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 code-review, \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043f\u043b\u043e\u0445\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0434 \u043d\u0430 C++, \u0445\u043e\u0442\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u0436\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041a\u043e\u0434 \u0431\u044b\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">class SomeServiceClient { public:   SomeServiceClient();   virtual ~SomeServiceClient();   bool CallAsync(const std::string &amp;uri, const std::string &amp;param,                  const misc::BusServiceClient::ResponseCB &amp;callback);   bool CallSync(const std::string &amp;uri, const std::string &amp;param,                 const misc::BusServiceClient::ResponseCB &amp;callback);  private:   misc::BusServiceClient ss_client_;    static const int kSleepMs = 100;   static const int kSleepCountMax = 50; };  class SpecificUrlFetcher : public UrlFetcher { public:   SpecificUrlFetcher();   virtual ~SpecificUrlFetcher();    SomeData FetchData(const URL &amp;url, const UrlFetcher::ResponseCB &amp;callback);  private:   bool SsResponse_returnValue{false};   char SsResponse_url[1024];    void SsResponseCallback(const std::string &amp;response);    SomeServiceClient *ss_client_; };  \/\/ ...  static const char ss_getlocalfile_uri[] = \"bus:\/\/url_replace_service\";  namespace net {  pthread_mutex_t g_url_change_callback_lock = PTHREAD_MUTEX_INITIALIZER;  SomeBusServiceClient::SomeBusServiceClient()     : ss_client_(misc::BusServiceClient::PrivateBus) {}  SomeBusServiceClient::~SomeBusServiceClient() {}  bool SomeBusServiceClient::CallAsync(     const std::string &amp;uri, const std::string &amp;param,     const misc::BusServiceClient::ResponseCB &amp;callback) {   bool bRet;   bRet = ss_client_.callASync(uri, param, callback);   return bRet; }  bool SomeBusServiceClient::CallSync(     const std::string &amp;uri, const std::string &amp;param,     const misc::BusServiceClient::ResponseCB &amp;callback) {   boold bRet bRet = false;   int counter;    pthread_mutex_lock(&amp;g_url_change_callback_lock);   ss_client_.callASync(uri, param, callback);    counter = 0;   for (;;) {     int r = pthread_mutex_trylock(&amp;g_url_change_callback_lock);     if (r == 0) {       bRet = true;       pthread_mutex_unlock(&amp;g_url_change_callback_lock);     } else if (r == EBUSY) {       usleep(kSleepMs);       counter++;       if (counter &gt;= kSleepCountMax) {         pthread_mutex_unlock(&amp;g_url_change_callback_lock);         break;       } else         continue;     }     break;   }   return bRet; }  \/**************************************************************************\/  SpecificUrlFetcher::SpecificUrlFetcher() {} SpecificUrlFetcher::~SpecificUrlFetcher() {}  void SpecificUrlFetcher::SsResponseCallback(const std::string &amp;response) {   std::unique_ptr&lt;lib::Value&gt; value(lib::JSONReader::Read(response));   if (!value.get() || !value-&gt;is_dict()) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }    lib::DictionaryValue *response_data =       static_cast&lt;lib::DictionaryValue *&gt;(value.get());   bool returnValue;   if (!response_data-&gt;GetBoolean(\"returnValue\", &amp;returnValue) || !returnValue) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }    std::string url;   if (!response_data-&gt;GetString(\"url\", &amp;url)) {     pthread_mutex_unlock(&amp;g_url_change_callback_lock);     return;   }   SsResponse_returnValue = true;    size_t array_sz = arraysize(SsResponse_url);   strncpy(SsResponse_url, url.c_str(), array_sz);   SsResponse_url[array_sz - 1] = 0;    pthread_mutex_unlock(&amp;g_url_change_callback_lock); }  SomeData SpecificUrlFetcher::FetchData(const URL &amp;url,                                        const UrlFetcher::ResponseCB &amp;callback) {   lib::DictionaryValue dictionary;   std::string ss_request_payload;    misc::BusServiceClient::ResponseCB response_cb =       lib::Bind(&amp;SpecificUrlFetcher::SsResponseCallback, this);    SomeBusServiceClient *ss_client_ = new SomeBusServiceClient();    dictionary.SetString(\"url\", url.to_string());   lib::JSONWriter::Write(dictionary, &amp;ss_request_payload);    SsResponse_returnValue = false;   SsResponse_url[0] = 0x00;    ss_client_-&gt;CallSync(ss_getlocalfile_uri, ss_request_payload, response_cb);   URL new_url;   if (SsResponse_returnValue) {     new_url = URL::from_string(SsResponse_url);   }    delete ss_client_;   return UrlFetcher::FetchData(new_url, callback); }  } \/\/ namespace net<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c, \u043d\u0430\u0436\u0438\u043c\u0430\u0439\u0442\u0435 \u043d\u0430 \u043d\u0435\u0433\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e, \u043f\u0443\u0442\u0438 \u043d\u0430\u0437\u0430\u0434 \u0443\u0436\u0435 \u043d\u0435\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u0430\u043a, \u043e\u0442\u0432\u0435\u0442\u044b.<\/summary>\n<div class=\"spoiler__content\">\n<ol>\n<li>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043b\u0430\u0441\u0441 UrlFetcher, \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 &#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e URL&#8217;\u0443. \u0423\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0448\u0438\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0439 URL, \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0435\u043a\u0438\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 URL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u042d\u0442\u0430\u043a\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d Decorator.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u043c\u0435\u043b\u043e\u0447\u0430\u043c:<\/p>\n<p>1. ss_getlocalfile_uri &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u0417\u0430\u0447\u0435\u043c? \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0435\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>2. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u0449\u0435\u0439 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0435 \u0435\u0439 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c.<\/p>\n<p>3. \u0421\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 SsResponse_returnValue <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e-\u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f pthread-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438 \u0442\u043e\u043c \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 std::thread, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>5. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0421\u0438-\u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 strncpy(); \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::string \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>6. ss_client_ \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u044b\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::unique_ptr.<\/p>\n<p>7. \u0412\u043c\u0435\u0441\u0442\u043e usleep() \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::this_thread::sleep()<\/p>\n<p>\u0415\u0449\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>8. \u0412 \u0446\u0438\u043a\u043b\u0435 \u0432 SomeBusServiceClient::CallSync \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0431\u044d\u043a \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043f\u0440\u0438\u0434\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0437\u0430 kSleepMs \u0434\u043e kSleepCountMax, \u0442\u043e \u043c\u044b \u043e\u0442\u043a\u0438\u043d\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443. \u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0449\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435:<\/p>\n<p>9. \u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 message bus \u0438 \u0436\u0434\u0435\u043c. \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u043d\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 message bus, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a kSleepCountMax*kSleepMs, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0430\u043c \u0441\u0442\u0430\u043b \u043d\u0435 \u043d\u0443\u0436\u0435\u043d (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e callASync \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c id \u0437\u0430\u043f\u0440\u043e\u0441\u0430?). \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u0436\u0434\u0435\u043c, \u0430 \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u0449\u0438\u0439 URL, \u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u044b\u0439 \u0431\u0430\u0440\u0434\u0430\u043a.<\/p>\n<p>9. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 FetchData \u043d\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443, new_url \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0439.<\/p>\n<p>10. \u041c\u0435\u0442\u043e\u0434 FetchUrl, \u0441\u0443\u0434\u044f \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439. \u0412 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0436\u0435 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 &#8212; WTF? \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e? \u0418 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e \u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435?<\/p>\n<p>11. \u0421\u0443\u0434\u044f \u043f\u043e \u043b\u043e\u0433\u0438\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u044b (\u0432\u044b\u0437\u043e\u0432 FetchUrl \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0435\u0434), SsResponseCallback \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0442\u0440\u0435\u0434\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0442 \u043d\u0435 \u0432 \u0442\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0433\u0434\u0435 \u043c\u044b \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438. \u0414\u043b\u044f pthread \u044d\u0442\u043e \u044f\u0432\u043d\u044b\u0439 undefined behavior.<\/p>\n<p>12. \u0426\u0435\u043d\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043e\u0442 <a class=\"mention\" href=\"\/users\/snizovtsev\">@snizovtsev<\/a>: &#171;&#8230;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u043b\u044c\u0437\u044f. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 2 \u0440\u0430\u0437\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f unlock. \u0422.\u0435. \u043a\u043e\u0434 \u043d\u0435\u0432\u0435\u0440\u0435\u043d \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435  \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0451 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430 condition variable&#187;<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u043e\u0442 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430\u043c\u0438 C++ \u0438 \u0445\u043e\u0440\u043e\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438, \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0434\u043e\u0442\u043e\u0448\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e \u0438 \u0443\u043c\u0435\u043d\u0438\u0438 &#171;\u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c&#187; \u043a\u043e\u0434 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435. \u041d\u0443 \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0430 \u043f\u043e \u0434\u0443\u0448\u0430\u043c.<\/p>\n<\/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\/551202\/\"> https:\/\/habr.com\/ru\/post\/551202\/<\/a><br \/><\/br><\/br><\/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-321062","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321062","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=321062"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321062\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}