MCPcopy Create free account
hub / github.com/apache/qpid-proton / receive_thread

Function receive_thread

cpp/examples/multithreaded_client_flow_control.cpp:247–261  ·  view source on GitHub ↗

Receive messages till atomic remaining count is 0. remaining is shared among all receiving threads

Source from the content-addressed store, hash-verified

245// Receive messages till atomic remaining count is 0.
246// remaining is shared among all receiving threads
247void receive_thread(receiver& r, std::atomic_int& remaining) {
248 try {
249 auto id = std::this_thread::get_id();
250 int n = 0;
251 // atomically check and decrement remaining *before* receiving.
252 // If it is 0 or less then return, as there are no more
253 // messages to receive so calling r.receive() would block forever.
254 while (remaining-- > 0) {
255 auto m = r.receive();
256 ++n;
257 OUT(std::cout << id << " received \"" << m.body() << '"' << std::endl);
258 }
259 OUT(std::cout << id << " received " << n << " messages" << std::endl);
260 } catch (const closed&) {}
261}
262
263int main(int argc, const char **argv) {
264 try {

Callers 1

mainFunction · 0.85

Calls 2

bodyMethod · 0.80
receiveMethod · 0.45

Tested by

no test coverage detected