The design that you've given is thread-safe as stated. CQs and all flavors 
of the Next operation have been designed to be thread-safe from the 
beginning.

However: moving forward, let me suggest that you use the 2-phase async 
client call APIs. 1-phase is sufficient for unary calls, but any kind of 
streaming call will need additional synchronization unless you use the 
2-phase calls. An example of the 2-phase unary call is given in 
examples/cpp/helloworld but the basic form would be:

call->response_reader = stub->PrepareAsyncRPC(&call->context, request, cq);
call->response_reader->StartCall();

For consistency, we're recommending the use of the 2-phase calls for 
multi-threaded code even for unary calls. We will eventually provide 
guidance along these lines when building the library with debug options.

Best regards,
Vijay Pai

On Saturday, October 28, 2017 at 5:19:08 PM UTC-7, [email protected] 
wrote:
>
> I want to have multiple async client threads (each thread may or may not 
> communicate with a different server) that send requests asynchronously 
> using a single global completion queue:
>
> global cq:
> CompletionQueue* cq = new CompletionQueue();
>
> actual rpc call:
> AsyncClientCall* call = new AsyncClientCall;
> call->response_reader = stub_->AsyncRPC(&call->context, request, cq);
>
> I also have multiple response collection threads, that wish to collect 
> responses from this global cq using Next():
> void* tag;
> bool ok = false;
> cq.Next(&tag, &ok);
>
> I know that Next() is a thread safe operation. I want to find out if 
> thread safety still exists between the client threads that are trying to 
> send a request using the global cq, and the response collection threads 
> that are listening on the same global cq.
> If this design is not thread safe, what is the best way to implement this 
> functionality without having to poll multiple completion queues?
>
> Thanks!
>
> Regards,
> Akshitha
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/63f33b2e-0d01-469c-8e39-c844cbf36d43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to