rdhabalia commented on a change in pull request #577: CPP add receiveAsync API
URL: https://github.com/apache/incubator-pulsar/pull/577#discussion_r130207983
##########
File path: pulsar-client-cpp/lib/PartitionedConsumerImpl.cc
##########
@@ -318,10 +345,44 @@ namespace pulsar {
void PartitionedConsumerImpl::messageReceived(Consumer consumer, const
Message& msg) {
Review comment:
for `receiveAsync`, we need to access `pendingReceives_` and `messages_`
atomically. so, if we release lock before pushing to `messages_` then it will
face race condition while receiving msg using `receiveAsync` and callback will
never be called.
eg:
- thread-1 comes to `receiveAsync()` which first checks `messages_` if it's
empty then it adds callback into `pendingReceives_`
- thread-2: in this method, if it adds the message into the `messages_`
same time then : message will sit into `messages_` queue and will never be
notified for receiveAsync-Callback.
Therefore, we need separate mutex to access `pendingReceives_` and
`messages_` atomically.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services