From 5b2bef71a980ead69e616e6e94fcd53a85b53275 Mon Sep 17 00:00:00 2001 From: sauron Date: Sun, 7 Sep 2025 00:27:38 +0900 Subject: [PATCH] commit 2025-09-07 12:27 add ZCppMainTest/ZtCThreadEx_002_MutexCond.cpp --- ZCppMain/ZCProcess_Win.H | 2 +- ZCppMain/ZMainHeadEx.H | 10 +- ZCppMainTest/ZtCThreadEx_000.cpp | 14 +- ZCppMainTest/ZtCThreadEx_001.cpp | 13 +- ZCppMainTest/ZtCThreadEx_002_MutexCond.cpp | 234 +++++++++++++++++++++++++++++ 5 files changed, 257 insertions(+), 16 deletions(-) create mode 100644 ZCppMainTest/ZtCThreadEx_002_MutexCond.cpp diff --git a/ZCppMain/ZCProcess_Win.H b/ZCppMain/ZCProcess_Win.H index aad9023..bcb9507 100644 --- a/ZCppMain/ZCProcess_Win.H +++ b/ZCppMain/ZCProcess_Win.H @@ -2380,7 +2380,7 @@ namespace ZNsMain { if(::SleepConditionVariableCS(&mo_CondVar, &mo_CritSect, AI_Mili)==TRUE) { - return ZNsEnum::ZEThread_OK; /*#####################################*/ + return ZNsEnum::ZEThread_OK; }/* if(::SleepConditionVariableCS(&mo_CondVar, &mo_CritSect, AI_Mili)==TRUE)*/ diff --git a/ZCppMain/ZMainHeadEx.H b/ZCppMain/ZMainHeadEx.H index d17ea84..f8aaa6b 100644 --- a/ZCppMain/ZMainHeadEx.H +++ b/ZCppMain/ZMainHeadEx.H @@ -222,11 +222,11 @@ namespace ZNsMain inline bool ZfPutEnv(const char* APC_EnvName, const char* APC_Value) { - #if __VISUAL_CPP_VER__>=200500 + #if __VISUAL_CPP_VER__>=200500 return ::_putenv_s(APC_EnvName, APC_Value)==0; - #else //__VISUAL_CPP_VER__<200500 + #else //__VISUAL_CPP_VER__<=200500 std::string VO_CStringEnv; @@ -250,9 +250,9 @@ namespace ZNsMain { // 표준 출력에 쓴다. - DWORD VDW_WrittenSize=0; + DWORD VDW_WrittenSize= 0 ; - const bool CB_IsOK = ////////////////////////////////////////// + const bool CB_IsOK = //////////////////////////////////////// ( ::WriteFile ( @@ -263,7 +263,7 @@ namespace ZNsMain ); /////////////////////////////////////////////////////////////// - if(CB_IsOK==false) return -1; return VDW_WrittenSize; + if(CB_IsOK==false) return -1; return VDW_WrittenSize; }/* inline long ZfWriteStdOut(LPCVOID APC_Buffer, DWORD ADW_BuffSize, LPOVERLAPPED AP_Overlapped=NULL)*/ diff --git a/ZCppMainTest/ZtCThreadEx_000.cpp b/ZCppMainTest/ZtCThreadEx_000.cpp index d510d6f..633dee3 100644 --- a/ZCppMainTest/ZtCThreadEx_000.cpp +++ b/ZCppMainTest/ZtCThreadEx_000.cpp @@ -115,18 +115,22 @@ namespace ZNsMain static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0) { - CThreadMy VO_CThreadMy ; + CThreadMy VO_CThreadMy1 ; + CThreadMy VO_CThreadMy2 ; + CThreadMy VO_CThreadMy3 ; + CThreadMy VO_CThreadMy4 ; + ZCStringStd VO_ZCStringStd1("Help Data1"); ZCStringStd VO_ZCStringStd2("Help Data2"); ZCStringStd VO_ZCStringStd3("Help Data3"); - VO_CThreadMy.Make(); + VO_CThreadMy1.Make(); cout<<"# Press Enter to continue."< +#include "ZCppMain/ZCProcess.H" +#include "ZCppMain/ZMainHeadEx.H" + + +using namespace std ; +using namespace ZNsMain; + + +const int CI_RepeatCnt = 3 ; +const int CI_WaitMilli = 1000 ; + + +namespace ZNsMain +{ + + namespace ZNsExam + { + + template class ZtCExamThread_002 + { + public: + typedef ZtCMutexCondData<> ZCMutexCondData; + public: + + class ZCThreadMy : public ZNsMain::ZtCThreadEx + { + public : + typedef ZNsMain::ZtCThreadEx TypeBase; + public : + friend class ZNsMain:: ZtCThreadEx; + private: + + void Init(ZCMutexCondData& AR_CMutexCond) + { + this->TypeBase::template Init(AR_CMutexCond); + + /*@@@@@@@@@*/ AR_CMutexCond.Lock(); /*@@@@@@@@@*/ + { + __for1(int, i, CI_RepeatCnt) + { + cout<<"# *** Thread Init "<TypeBase::template Exec(AR_CMutexCond); + { + __for1(int, i, CI_RepeatCnt) + { + cout<<"# >>> Thread Exec "<TypeBase::template Fini(AR_CMutexCond); + { + __for1(int, i, CI_RepeatCnt) + { + cout<<"# *** Thread Fini "<*/ + + + static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0) + { + ZCMutexCondData VO_CMutexCond; + ZCThreadMy VO_CThreadMy ; + + VO_CMutexCond.InitCond(); + cout<<"- Mutex Init Cond" < class ZtCExamThread_002*/ + + }/* + namespace ZNsExam*/ + +}/* +namespace ZNsMain*/ + + +int main(int AI_ArgCnt, char* APP_ArgVal[]) +{ + return ZNsMain::ZNsExam:: + + ZtCExamThread_002<>::Main(AI_ArgCnt, APP_ArgVal); +}/* +int main(int AI_ArgCnt, char* APP_ArgVal[])*/ + + +/*//////////////////////////////////////////////////////////////////////////////////////// + +■ cigwin 컴파일 + + // g++ -mno-cygwin -o ZtCThreadEx_002_MutexCond.exe ZtCThreadEx_002_MutexCond.cpp -I../../my_CPP/CPP_Main/ -I../../my_CPP/CPP_Std/ -D__CYGWIN32__ -D__VISUAL_CPP_VER__=200300 + // g++ -mno-cygwin -o ZtCThreadEx_002_MutexCond_D.exe ZtCThreadEx_002_MutexCond.cpp -I../../my_CPP/CPP_Main/ -I../../my_CPP/CPP_Std/ -D__CYGWIN32__ -D__VISUAL_CPP_VER__=200300 -D_DEBUG + +■ mingw 컴파일 + + g++.exe -std=c++98 -o ZtCThreadEx_002_MutexCond_mw.exe ZtCThreadEx_002_MutexCond.cpp -I../ -lWs2_32 + g++.exe -std=c++98 -o ZtCThreadEx_002_MutexCond_mw_D.exe ZtCThreadEx_002_MutexCond.cpp -I../ -lWs2_32 -D_DEBUG + + ./ZtCThreadEx_002_MutexCond_mw.exe + ./ZtCThreadEx_002_MutexCond_mw_D.exe + + + Administrator@q381-2673 UCRT64 /e/my_CPP/ZCpp/ZCppMainTest + # date + Sun Aug 24 10:47:09 KST 2025 + + Administrator@q381-2673 UCRT64 /e/my_CPP/ZCpp/ZCppMainTest + # g++ --version + g++.exe (Rev2, Built by MSYS2 project) 13.2.0 + Copyright (C) 2023 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + +■ Linux 컴파일 + + g++ -std=c++98 -o ZtCThreadEx_002_MutexCond.exe ZtCThreadEx_002_MutexCond.cpp -I../ -lpthread + g++ -std=c++98 -o ZtCThreadEx_002_MutexCond_D.exe ZtCThreadEx_002_MutexCond.cpp -I../ -lpthread -D_DEBUG + + sauron@q381-2673:/mnt/e/my_CPP/ZCpp/ZCppMainTest$ gcc --version + gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 + Copyright (C) 2019 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + sauron@q381-2673:/mnt/e/my_CPP/ZCpp/ZCppMainTest$ date + Sun Aug 24 00:05:51 DST 2025 + + sauron@q381-2673:/mnt/e/my_CPP/ZCpp/ZCppMainTest$ cat /etc/os-release + NAME="Ubuntu" + VERSION="20.04.6 LTS (Focal Fossa)" + ID=ubuntu + ID_LIKE=debian + PRETTY_NAME="Ubuntu 20.04.6 LTS" + VERSION_ID="20.04" + HOME_URL="https://www.ubuntu.com/" + SUPPORT_URL="https://help.ubuntu.com/" + BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" + PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" + VERSION_CODENAME=focal + UBUNTU_CODENAME=focal + + + [sauron@q381-2657 ZCppMainTest]$ cat /etc/centos-release + CentOS Linux release 7.9.2009 (Core) + + [sauron@q381-2657 ZCppMainTest]$ g++ --version + g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44) + Copyright (C) 2015 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +■ 실행 + + ./ZtCThreadEx_002_MutexCond.exe + ./ZtCThreadEx_002_MutexCond_D.exe + +////////////////////////////////////////////////////////////////////////////////////////*/