ServerAsyncResponseWriter::Finish thread-safety

54 views
Skip to first unread message

nic...@verbsurgical.com

unread,
May 22, 2018, 7:08:07 PM5/22/18
to grpc.io
Hi,

I have a question about the use of ServerAsyncResponseWriter objects.  If I have a thread that is running a completion queue, ie.:
// Completion queue thread does:
void Run() {
 
for (;;) {
   
void* tag = nullptr;
   
bool ok = false;
   
bool has_event = completion_queue_->Next(&tag, &ok);
   
static_cast<CallData*>(tag)->Next(ok);
 
}
}


class CallData {
 
public:
 
// similar to example code here:
 
// https://github.com/grpc/grpc/blob/f2979e32185804ee707ab18da844d74496aeb479/examples/cpp/helloworld/greeter_async_server.cc#L99
 
void Next(bool ok) {
   
if (status_ == CREATE) {
   
//...
   
} else if (status_ == PROCESS) {
   
// call initialization... create new request handler, etc..
   
// 'The actual processing', ie. running the request, we would like
   
// to pass this out to separate thread.  Something like:
    other_app_thread_
->PostTask(handle_request_callback(request)); // non-blocking PostTask
   
return;
 
}
 
//...
 
private:
 
ServerAsyncResponseWriter<HelloReply> responder_;
 
// ...
};



    Can the |handle_request_callback| function invoke responder_.Finish(...) on another thread, while the completion queue is blocking at completion_queue_->Next(...) ?  If it is thread-safe, will it prompt the completion queue to complete the call (send the response), and appropriately invoke the CallData tag again when ready to enter the FINISHED state and delete this CallData object?

This question probably more generally applies to other async_unary_call.h classes.

Thanks!
Nick


Reply all
Reply to author
Forward
0 new messages