/////////////////////////////////////////////////////////////// // MT1-Q5.cpp - pass messages between threads // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2019 // /////////////////////////////////////////////////////////////// #include "../Cpp11-BlockingQueue/Cpp11-BlockingQueue.h" #include #include void threadProc(BlockingQueue& bQueue) { while (true) { std::string msg = bQueue.deQ(); std::cout << "\n " << msg; if (msg == "quit") { std::cout << "\n That's all folks\n\n"; break; } } } int main() { std::cout << "\n MT1-Q5 - pass string messages between threads"; std::cout << "\n -----------------------------------------------\n"; BlockingQueue bQueue; std::thread trd(threadProc, std::ref(bQueue)); for (int i = 1; i < 11; ++i) { std::string msg = "msg #" + std::to_string(i); bQueue.enQ(msg); } bQueue.enQ("quit"); trd.join(); std::cout << "\n\n"; }