gRPC: Asynchronous client thread safety clarification

13 Views Asked by At

In gRPC, we can use an async client to send multiple calls at the same time. For example, with a service that has a RPC method Foo(), we need to call, in this order:

  1. First auto reader = stub.AsyncFoo(&client_context, request, &completion_queue)
  2. Then reader->Finish(&response, &status, call_data)
  3. Finally completion_queue.Next() to get the status of the RPC.

My questions about thread safety are the following:

  1. Is it thread safe to call Next() and AsyncFoo() at the same time in different threads?
  2. Is it thread safe to call Next() and Finish() at the same time in different threads?
  3. Is it thread safe to call multiple AsyncFoo() for different call data at the same time in different thread?
  4. Is it thread safe to call multiple Finish() for different call data at the same time in different thread?
  5. For all the cases, if it is thread-safe: Is it thread-safe only when different threads are working with different stub or does it work also for the same stub?
0

There are 0 best solutions below