소스 검색

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);