/////////////////////////////////////////////////////////////////////// // Notifier.cpp - Enable child thread to notify parent thread // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2016 // /////////////////////////////////////////////////////////////////////// #include #include "Notifier.h" #include "../Utilities/Utilities.h" //----< function to run asynchronously >------------------------------- void compute(INotifier* pNotifier) { for (size_t i = 0; i < 100; ++i) if (i % 10 == 0) pNotifier->invokeEventProcessing(i); } /////////////////////////////////////////////////////////////////////// // Demonstration of notifier using Utils = Utilities::StringHelper; int main() { Utils::Title("Demonstrating Notification from Child Thread"); class NotifyObject : public INotify { virtual void doNotify(size_t reportedValue) { std::cout << "\n notified that value is " << reportedValue; } } nObj; using Fptr = void(*)(INotifier*); // matches compute function Notifier notifier; notifier.reg(&nObj); std::thread t = notifier.asyncRun(compute); // do other useful work here t.join(); std::cout << "\n\n"; }