gRPC C++ server streaming reactor: Is it possible to sync StartWrite with OnDone

12 views
Skip to first unread message

John Smith

unread,
10:21 AM (6 hours ago) 10:21 AM
to grpc.io
Hi, in my scenario, I need to initiate writing to the stream from my application thread when the data is ready. It is unclear what to do in situations that lead to the RPC closing and the OnDone call at the end.

> Thread safety: the above calls may take place concurrently, except that OnDone will always take place after all other reactions. No further RPC operations are permitted to be issued after OnDone is invoked.

It is possible to organize the code so that StartWrite calls are only from the grpc threads, but in this case there is no way to tell the reactor to check for new data to send.
Mark D. Roth said that it is possible to call StartWrite from a user thread (thank you very much for your help, Mark):
There's no requirement that `StartWrite()` can be called only from a reactor thread -- you can call that from anywhere, as long as you have proper synchronization. The only requirement is that there can be only one write pending at a time.

But how to synchronize the StartWrite call from the user thread with the OnDone call  from the reactor thread ? Is this even possible?

P.S. experiments show that if StartWrite is called after entering OnDone and we wait for OnWriteDone to be called while we are in OnDone, it is still UB, since OnWriteDone will be followed by MayBeDone 


Reply all
Reply to author
Forward
0 new messages