diff --git a/ControlApp/ControlApp.cpp b/ControlApp/ControlApp.cpp index 6d3eaf3..dc0e4fc 100644 --- a/ControlApp/ControlApp.cpp +++ b/ControlApp/ControlApp.cpp @@ -6,8 +6,8 @@ int main() { - Run r1; - Run r2; + Run r1(20); + Run r2(10); char input = '0'; r2.setState(AUTO); @@ -18,10 +18,10 @@ int main() std::cout << "Hello World!\n"; - std::cout << "Q: Quit\n"; - while (input != 'Q') { - std::cin >> input; - } + //std::cout << "Q: Quit\n"; + //while (input != 'Q') { + // std::cin >> input; + //} r1.EndTask(); r2.EndTask(); @@ -29,6 +29,8 @@ int main() std::cout << "Wait Terminate!\n"; r1.WaitThreadTerminate(); r2.WaitThreadTerminate(); + + std::cout << "All Terminated!\n"; } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu diff --git a/ControlApp/Run.cpp b/ControlApp/Run.cpp index 1e34f27..4c5368d 100644 --- a/ControlApp/Run.cpp +++ b/ControlApp/Run.cpp @@ -1,14 +1,20 @@ #include "Run.h" #include -Run::Run() { +Run::Run(int count) { // constructor m_bExit = false; m_bHalt = false; m_state = IDLE; - m_myThread = std::thread(&Run::DoTask, this); + //m_myThread = std::thread(&Run::DoTask, this); + // assign a member function of a class + // @link https://thispointer.com//c11-multithreading-part-3-carefully-pass-arguments-to-threads/ + //new_thread dummyObj; + //m_myThread = std::thread(&new_thread::operator(), &dummyObj, 1); + + m_myThread = std::thread(new_thread(), count); } Run::~Run() diff --git a/ControlApp/Run.h b/ControlApp/Run.h index e3dfafe..8c44cb9 100644 --- a/ControlApp/Run.h +++ b/ControlApp/Run.h @@ -31,7 +31,7 @@ class Run { public : // ctor - Run(); + Run(int count = 1); virtual ~Run();