diff --git a/README.md b/README.md index d731fd2..28dc725 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -V1.1.0 +## V1.1.0 ### 新增: -实现`ThreadBase`类,创建单个线程 +实现 `ThreadBase`类,创建单个线程 + +## V1.1.0 + +### 新增: + +创建多个线程 diff --git a/code/main.cpp b/code/main.cpp index 62bcf8c..767f868 100644 --- a/code/main.cpp +++ b/code/main.cpp @@ -7,11 +7,12 @@ public: void ThreadBase_ThreadLoopFunc(int tInputFlag, void *pInputArg) override { std::string *pTempMSG = (std::string *)pInputArg; - for (int tTempN = 0; tTempN < 5; tTempN++) + for (int i = 0; i < 3; i++) { - std::cout << "[子线程] flag=" << tInputFlag - << " pTempMSG=" << *pTempMSG - << " tTempN=" << tTempN << std::endl; + std::cout << "[子线程 " << pthread_self() + << "] flag=" << tInputFlag + << " msg=" << *pTempMSG + << " i=" << i << std::endl; sleep(1); } } @@ -19,15 +20,23 @@ public: int main(int argc, char **argv) { - MyThread tTempThread; - std::string tTempString = "HelloThread"; + // 创建多个线程对象 + MyThread tTempThread1, tTempThread2, tTempThread3; + std::string tTempString1 = "线程一"; + std::string tTempString2 = "线程二"; + std::string tTempString3 = "线程三"; - /* 启动线程 */ - std::cout << "[主线程] 创建线程..." << std::endl; - tTempThread.ThreadBase_ThreadCreate(123, &tTempString); - /* 等待子线程退出 */ - tTempThread.ThreadBase_ThreadJoin(); - std::cout << "[主线程] 线程已退出" << std::endl; + std::cout << "[主线程] 创建子线程..." << std::endl; + tTempThread1.ThreadBase_ThreadCreate(101, &tTempString1); + tTempThread2.ThreadBase_ThreadCreate(202, &tTempString2); + tTempThread3.ThreadBase_ThreadCreate(303, &tTempString3); + + // 等待所有线程退出 + tTempThread1.ThreadBase_ThreadJoin(); + tTempThread2.ThreadBase_ThreadJoin(); + tTempThread3.ThreadBase_ThreadJoin(); + + std::cout << "[主线程] 所有子线程已退出" << std::endl; return 0; -} +} \ No newline at end of file