238 lines
8.4 KiB
C++
238 lines
8.4 KiB
C++
|
|
|
|
#ifndef _REENTRANT_EX
|
|
#define _REENTRANT_EX
|
|
#endif
|
|
|
|
|
|
#include <iostream>
|
|
#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<typename TDummy=void*> class ZtCExamThread_002
|
|
{
|
|
public:
|
|
typedef ZtCMutexCondData<> ZCMutexCondData;
|
|
public:
|
|
|
|
class ZCThreadMy : public ZNsMain::ZtCThreadEx<ZCThreadMy>
|
|
{
|
|
public :
|
|
typedef ZNsMain::ZtCThreadEx<ZCThreadMy> TypeBase;
|
|
public :
|
|
friend class ZNsMain:: ZtCThreadEx<ZCThreadMy>;
|
|
private:
|
|
|
|
void Init(ZCMutexCondData& AR_CMutexCond)
|
|
{
|
|
this->TypeBase::template Init<ZCMutexCondData&>(AR_CMutexCond);
|
|
|
|
/*@@@@@@@@@*/ AR_CMutexCond.Lock(); /*@@@@@@@@@*/
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"# *** Thread Init "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
/*::::::::::::::::::::::::*/
|
|
}
|
|
AR_CMutexCond.WakeCond();
|
|
AR_CMutexCond.WaitCond();
|
|
}/*
|
|
void Init(ZCMutexCondData& AR_CMutexCond)*/
|
|
|
|
void Exec(ZCMutexCondData& AR_CMutexCond)
|
|
{
|
|
this->TypeBase::template Exec<ZCMutexCondData&>(AR_CMutexCond);
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"# >>> Thread Exec "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
/*::::::::::::::::::::::::*/
|
|
}
|
|
AR_CMutexCond.WakeCond();
|
|
AR_CMutexCond.WaitCond();
|
|
}/*
|
|
void Exec(ZCMutexCondData& AR_CMutexCond)*/
|
|
|
|
void Fini(ZCMutexCondData& AR_CMutexCond)
|
|
{
|
|
this->TypeBase::template Fini<ZCMutexCondData&>(AR_CMutexCond);
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"# *** Thread Fini "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
/*::::::::::::::::::::::::*/
|
|
}
|
|
AR_CMutexCond.WakeCond();
|
|
|
|
/*@@@@@@@@@*/ AR_CMutexCond.UnLock(); /*@@@@@@@@@*/
|
|
}/*
|
|
void Fini(ZCMutexCondData& AR_CMutexCond)*/
|
|
|
|
private:
|
|
};/*
|
|
class ZCThreadMy : public ZNsMain::ZtCThreadEx<ZCThreadMy>*/
|
|
|
|
|
|
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)
|
|
{
|
|
ZCMutexCondData VO_CMutexCond;
|
|
ZCThreadMy VO_CThreadMy ;
|
|
|
|
VO_CMutexCond.InitCond();
|
|
cout<<"- Mutex Init Cond" <<endl;
|
|
VO_CMutexCond.Lock ();
|
|
{
|
|
VO_CThreadMy.Make(ZftMCP(VO_CMutexCond));
|
|
cout<<"- Wait Thread Init"<<endl;
|
|
VO_CMutexCond.WaitCond();
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"- Ack Thread Init "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
}
|
|
VO_CMutexCond.WakeCond();
|
|
cout<<"- Wait Thread Exec"<<endl;
|
|
VO_CMutexCond.WaitCond();
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"- Ack Thread Exec "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
/*::::::::::::::::::::::::*/
|
|
}
|
|
VO_CMutexCond.WakeCond();
|
|
cout<<"- Wait Thread Fini"<<endl;
|
|
VO_CMutexCond.WaitCond();
|
|
{
|
|
__for1(int, i, CI_RepeatCnt)
|
|
{
|
|
cout<<"- Ack Thread Fini "<<i<<endl; ZfSuspendExec(CI_WaitMilli);
|
|
}
|
|
/*::::::::::::::::::::::::*/
|
|
}
|
|
}
|
|
VO_CMutexCond.UnLock();
|
|
|
|
|
|
VO_CMutexCond.FiniCond(); cout<<"- Mutex Fini Cond" <<endl;
|
|
|
|
return 0;
|
|
}/*
|
|
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)*/
|
|
|
|
|
|
public:
|
|
};/*
|
|
template<typename TDummy=void*> 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[])*/
|
|
|
|
|
|
/*////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
■ cygwin 컴파일
|
|
|
|
// 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
|
|
|
|
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 -Wall -Wno-unused-function -Wno-misleading-indentation
|
|
g++ -std=c++98 -o ZtCThreadEx_002_MutexCond_D.exe ZtCThreadEx_002_MutexCond.cpp -I../ -lpthread -Wall -Wno-unused-function -Wno-misleading-indentation -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
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////*/
|