فهرست منبع

fix thread-safe

ithewei 1 سال پیش
والد
کامیت
6e0f701fe7
1فایلهای تغییر یافته به همراه3 افزوده شده و 0 حذف شده
  1. 3 0
      examples/protorpc/protorpc_client.cpp

+ 3 - 0
examples/protorpc/protorpc_client.cpp

@@ -122,6 +122,7 @@ public:
             calls_mutex.lock();
             auto iter = calls.find(res->id());
             if (iter == calls.end()) {
+                calls_mutex.unlock();
                 return;
             }
             auto ctx = iter->second;
@@ -147,7 +148,9 @@ public:
         req->id();
         auto ctx = std::make_shared<protorpc::ProtoRpcContext>();
         ctx->req = req;
+        calls_mutex.lock();
         calls[req->id()] = ctx;
+        calls_mutex.unlock();
         // Request::SerializeToArray + protorpc_pack
         protorpc_message msg;
         protorpc_message_init(&msg);