diff --git a/ZCppMain/ZCProcess.H b/ZCppMain/ZCProcess.H index 2682b19..e593c5a 100644 --- a/ZCppMain/ZCProcess.H +++ b/ZCppMain/ZCProcess.H @@ -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;} diff --git a/ZCppMain/ZCProcess_Linux.H b/ZCppMain/ZCProcess_Linux.H index 2a3edf4..57df3c8 100644 --- a/ZCppMain/ZCProcess_Linux.H +++ b/ZCppMain/ZCProcess_Linux.H @@ -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__) diff --git a/ZCppMainTest/ZtCBaseList_000.cpp b/ZCppMainTest/ZtCBaseList_000.cpp index 9400cc7..85bab29 100644 --- a/ZCppMainTest/ZtCBaseList_000.cpp +++ b/ZCppMainTest/ZtCBaseList_000.cpp @@ -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 )<