// Receive messages till atomic remaining count is 0. // remaining is shared among all receiving threads void receive_thread(receiver& r, std::atomic_int& remaining) { try { auto id = std::this_thread::get_id(); int n = 0; // atomically check and decrement remaining *before* receiving. // If it is 0 or less then return, as there are no more // messages to receive so calling r.receive() would block forever. while (remaining-- > 0) { auto m = r.receive(); ++n; OUT(std::cout << id << " received \"" << m.body() << '"' << std::endl); } OUT(std::cout << id << " received " << n << " messages" << std::endl); } catch (const closed&) {} }
void messaging_handler::on_receiver_error(receiver &l) { on_error(l.error()); }
void handler::on_receiver_error(receiver &l) { on_error(l.error()); }