#include #include #include #include "03-ProducerConsumer.h" ProducerConsumerBuffer pcb; bool running = true; // producer thread runs this method void putMethod() { int cnt = 0; while (running) { cout << "putting " << cnt << endl; pcb.put(cnt++); usleep( rand() % 5000000 ); } cout << "put thread terminating" << endl; } // consumer method runs this method void getMethod() { int cnt; while (running) { cnt = pcb.get(); cout << "\tgot " << cnt << endl; usleep( rand() % 5000000 ); } cout << "get thread terminating" << endl; } // main() int main(int argc, char *argv[]) { thread putter(putMethod); thread getter(getMethod); string input; cout << "Type something and hit enter to quit: "; cin >> input; running = false; pcb.done(); putter.join(); getter.join(); cout << "Main thread terminating" << endl; }