commit 2025-10-06 19:02 edit a bit ZCppMain/ZCProcess.H
This commit is contained in:
@ -1101,6 +1101,16 @@ namespace ZNsMain
|
||||
|
||||
로 바뀌는 경우에, 쓰레드가 잠자고 있다면 깨운다. -- 2025-10-04 17:23
|
||||
|
||||
상태 this->mb_MustWait==true 를 만든 쓰레드는 '잠자는 쓰레드'이고
|
||||
상태 this->mb_MustWait==false 를 만든 쓰레드는 '깨우는 쓰레드'이다.
|
||||
|
||||
다시 풀어 쓰면,
|
||||
|
||||
상태 this->mb_MustWait==true 를 만든 쓰레드는 '소비자 쓰레드'이고
|
||||
상태 this->mb_MustWait==false 를 만든 쓰레드는 '생산자 쓰레드'이다.
|
||||
|
||||
-- 2025-10-06 18:29
|
||||
|
||||
////////////////////////////////////////////////////////////////*/
|
||||
|
||||
this->TMutexCondData::Lock();
|
||||
@ -1178,6 +1188,17 @@ namespace ZNsMain
|
||||
|
||||
-- 2025-10-04 19:07
|
||||
|
||||
바꿔 말하면,
|
||||
|
||||
1번 쓰레드는 '소비자 쓰레드'이고, 2번 쓰레드는 '생산자 쓰레드'
|
||||
|
||||
이다. 그래서
|
||||
|
||||
WaitCondBoolSync() 는 '소비자 쓰레드'에서 호출하고
|
||||
WakeCondBoolSync() 는 '생산자 쓰레드'에서 호출한다.
|
||||
|
||||
-- 2025-10-06 18:38
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
template< typename TMutexCondData=ZNsMain::ZtCMutexCondData<>
|
||||
@ -1188,18 +1209,21 @@ namespace ZNsMain
|
||||
typedef TMutexCondData TypeData ;
|
||||
typedef TMutexCondData CMutexCondData;
|
||||
protected:
|
||||
bool mb_WaitCond;
|
||||
bool mb_WaitCond; // 지금 쓰레드가 작업이 없어서 잠잔다.
|
||||
bool mb_WakeCond; // 어떤 쓰레드가 작업이 있어서 깨웠다.
|
||||
public :
|
||||
|
||||
ZtCMutexCondVar()
|
||||
{
|
||||
mb_WaitCond= false;
|
||||
mb_WakeCond= false;
|
||||
}/*
|
||||
ZtCMutexCondVar()*/
|
||||
|
||||
ZtCMutexCondVar(const ZtCMutexCondVar& rhs)
|
||||
{
|
||||
mb_WaitCond= false;
|
||||
mb_WakeCond= false;
|
||||
}/*
|
||||
ZtCMutexCondVar(const ZtCMutexCondVar& rhs)*/
|
||||
|
||||
@ -1210,14 +1234,16 @@ namespace ZNsMain
|
||||
ZtCMutexCondVar& operator=(const ZtCMutexCondVar& rhs)*/
|
||||
|
||||
|
||||
_SY_ bool WaitCondOnExec()
|
||||
_SY_ bool WaitCondBoolSync()
|
||||
{
|
||||
/* 이 TMutexCondData 에 접근해 작업을 처리한 쓰레드
|
||||
(즉 '잠자는 쓰레드')는 작업이 끝나면 WaitCond()
|
||||
에서 대기한다.
|
||||
|
||||
즉 잠자는 쓰레드, 소비자 쓰레드
|
||||
|
||||
는 작업이 끝나면 WaitCond() 에서 대기한다.
|
||||
|
||||
다만, 이 함수로 2개 이상의 쓰레드가 대기하는 것은
|
||||
잘못된 설계이다. 어디까지나 1개 쓰레드 대기 용이다.
|
||||
잘못된 설계이다. 어디까지나 1 개 쓰레드 대기용이다.
|
||||
|
||||
-- 2025-10-04 18:21
|
||||
*/
|
||||
@ -1225,36 +1251,44 @@ namespace ZNsMain
|
||||
|
||||
this->TMutexCondData::Lock();
|
||||
{
|
||||
if(!this->mb_WaitCond)
|
||||
if(!this->mb_WakeCond && !this->mb_WaitCond)
|
||||
{
|
||||
this->mb_WaitCond = true ;
|
||||
this->TMutexCondData::WaitCond();
|
||||
this->mb_WaitCond = false;
|
||||
this->mb_WakeCond = false;
|
||||
|
||||
VB_Return = true;
|
||||
}/*
|
||||
if(!this->mb_WaitCond)*/
|
||||
if(!this->mb_WakeCond && !this->mb_WaitCond)*/
|
||||
}
|
||||
this->TMutexCondData::UnLock();
|
||||
|
||||
return VB_Return;
|
||||
}/*
|
||||
_SY_ bool WaitCondOnExec()*/
|
||||
_SY_ bool WaitCondBoolSync()*/
|
||||
|
||||
|
||||
_SY_ void WakeCondOnExec()
|
||||
_SY_ void WakeCondBoolSync()
|
||||
{
|
||||
/* 작업이 발생해, 이 TMutexCondData 에 접근해 해당
|
||||
쓰레드를 깨워 작업을 시키려는 쓰레드(깨우는 쓰레드)
|
||||
쓰레드를 깨워 작업을 시키려는 쓰레드
|
||||
|
||||
즉 깨우는 쓰레드, 생산자 쓰레드
|
||||
|
||||
가 호출한다. -- 2025-10-04 19:01
|
||||
*/
|
||||
this->TMutexCondData::Lock();
|
||||
{
|
||||
if(this->mb_WaitCond==true) this->TMutexCondData::WakeCond();
|
||||
if(!this->mb_WakeCond)
|
||||
{
|
||||
this->TMutexCondData::WakeCond(); this->mb_WakeCond=true;
|
||||
}/*
|
||||
if(!this->mb_WakeCond)*/
|
||||
}
|
||||
this->TMutexCondData::UnLock();
|
||||
}/*
|
||||
_SY_ void WakeCondOnExec()*/
|
||||
_SY_ void WakeCondBoolSync()*/
|
||||
|
||||
|
||||
bool DoWaitCond() const{return mb_WaitCond;}
|
||||
|
@ -3998,9 +3998,9 @@ namespace ZNsMain
|
||||
|
||||
///////////////////////////////////////////////////////////////*/
|
||||
|
||||
template< typename TData=ZNsMain::ZCEmpty
|
||||
template< typename TData=ZNsMain::ZCEmpty /////////////////////
|
||||
>
|
||||
class ZtCMutexCondData : public TData
|
||||
class ZtCMutexCondData : public TData ///////////////////////////
|
||||
{
|
||||
protected:
|
||||
pthread_mutex_t mh_Mutex;
|
||||
@ -4161,9 +4161,9 @@ namespace ZNsMain
|
||||
|
||||
public:
|
||||
};/*
|
||||
template< typename TData=ZNsMain::ZCEmpty
|
||||
template< typename TData=ZNsMain::ZCEmpty /////////////////////
|
||||
>
|
||||
class ZtCMutexCondData : public TData ///*/
|
||||
class ZtCMutexCondData : public TData ///////////////////*/
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////
|
||||
@ -4409,6 +4409,7 @@ namespace ZNsMain
|
||||
>
|
||||
class ZtCBarrier : public TData /////////*/
|
||||
|
||||
|
||||
#endif // !defined(__USE_XOPEN2K) || defined(__USE_MUTEX_COND_FOR_BARRIER__)
|
||||
|
||||
|
||||
|
@ -354,6 +354,18 @@ namespace ZNsMain
|
||||
static void ShowNode11_2(ZCLink11& AR_CLink, ostream& AR_OS, ZTypLong& ARRI_CallCnt)*/
|
||||
|
||||
|
||||
static void ShowNode10_3(ZCLink10& AR_CLink, ZTypLong& ARRI_CallCnt)
|
||||
{
|
||||
cout<<++ARRI_CallCnt<<" * Node10 Curr : " <<*(AR_CLink )<<endl;
|
||||
}/*
|
||||
static void ShowNode10_3(ZCLink10& AR_CLink, ZTypLong& ARRI_CallCnt)*/
|
||||
static void ShowNode11_3(ZCLink11& AR_CLink, ZTypLong& ARRI_CallCnt)
|
||||
{
|
||||
cout<<++ARRI_CallCnt<<" * Node11 Curr : " <<*(AR_CLink )<<endl;
|
||||
}/*
|
||||
static void ShowNode11_3(ZCLink11& AR_CLink, ZTypLong& ARRI_CallCnt)*/
|
||||
|
||||
|
||||
static int Main(int AI_ArgCnt=0, char* APP_ArgVal[]=0)
|
||||
{
|
||||
ZTypLong VI_CallCnt=0;
|
||||
@ -482,9 +494,9 @@ namespace ZNsMain
|
||||
|
||||
VO_ZCBaseListEx10.IterElemLink(&Append10);
|
||||
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
|
||||
VO_ZCBaseListEx10 .IterElemLink(&ShowNode10, ZftMCP(VI_CallCnt=0));
|
||||
VO_ZCBaseListEx10 .IterElemLink(&ShowNode10_3, ZftMCP(VI_CallCnt=0));
|
||||
cout<<"*****************************************************"<<endl;
|
||||
VO_ZCBaseListEx10_2.IterElemLink(&ShowNode10, ZftMCP(VI_CallCnt=0));
|
||||
VO_ZCBaseListEx10_2.IterElemLink(&ShowNode10_3, ZftMCP(VI_CallCnt=0));
|
||||
|
||||
|
||||
VO_ZCBaseListEx10.SendRangeOutAfter
|
||||
@ -498,9 +510,9 @@ namespace ZNsMain
|
||||
cout<<endl<<"# after VO_ZCBaseListEx10's 2~3th link to VO_ZCBaseListEx10_2's 2th link after"<<endl;
|
||||
|
||||
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
|
||||
VO_ZCBaseListEx10 .IterElemLink(&ShowNode10, ZftMCP(VI_CallCnt=0));
|
||||
VO_ZCBaseListEx10 .IterElemLink(&ShowNode10_3, ZftMCP(VI_CallCnt=0));
|
||||
cout<<"*****************************************************"<<endl;
|
||||
VO_ZCBaseListEx10_2.IterElemLink(&ShowNode10, ZftMCP(VI_CallCnt=0));
|
||||
VO_ZCBaseListEx10_2.IterElemLink(&ShowNode10_3, ZftMCP(VI_CallCnt=0));
|
||||
|
||||
return 0;
|
||||
}/*
|
||||
|
Reference in New Issue
Block a user