資源簡介
編寫一個多隊列線程池應用
編寫一個實現了整數加法運算的線程池
在這個應用中,有三種線程:
一個用戶線程。用于向線程池(主控線程)提出加法計算請求
一個主控線程。用于接收用戶線程發送的加法計算請求,并負載均衡地將請求下發到若干計算線程
若干計算線程。用于接收來自于主控線程轉發的加法計算請求,完成加法計算,并將計算結果直接返回給用戶線程
無論何種線程,每個線程都有自己的消息隊列
通過這些隊列,實現加法計算請求的發送與轉發,以及計算結果的返回
具體業務要求:
用戶線程需同時向主控線程提出>=1000個加法計算請求
用戶線程需要驗證是否收到了這些加法計算的結果
代碼片段和文件信息
#include?“CLConditionVariable.h“
#include?“CLMutex.h“
#include?“CLLog.h“
CLConditionVariable::CLConditionVariable()
{
int??r?=?pthread_cond_init(&m_ConditionVariable?0);
if(r?!=?0)
{
CLLog::WriteLogMsg(“In?CLConditionVariable::CLConditionVariable()?pthread_cond_init?error“?r);
throw?“In?CLConditionVariable::CLConditionVariable()?pthread_cond_init?error“;
}
}
CLConditionVariable::~CLConditionVariable()
{
int?r?=?pthread_cond_destroy(&m_ConditionVariable);
if(r?!=?0)
{
CLLog::WriteLogMsg(“In?CLConditionVariable::~CLConditionVariable()?pthread_cond_destroy?error“?r);
throw?“In?CLConditionVariable::~CLConditionVariable()?pthread_cond_destroy?error“;
}
}
CLStatus?CLConditionVariable::Wait(CLMutex?*pMutex)
{
int?r?=?pthread_cond_wait(&m_Condit
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-26?21:50??4\
?????文件????????1576??2011-08-24?22:02??4\CLConditionVariable.cpp
?????文件?????????554??2011-08-23?15:30??4\CLConditionVariable.h
?????文件?????????750??2011-08-29?17:19??4\CLCriticalSection.cpp
?????文件?????????406??2011-08-29?17:23??4\CLCriticalSection.h
?????文件????????1184??2011-08-29?17:44??4\CLEvent.cpp
?????文件?????????695??2011-09-13?15:20??4\CLEvent.h
?????文件?????????334??2010-08-13?18:57??4\CLExecutive.cpp
?????文件?????????867??2011-08-25?16:06??4\CLExecutive.h
?????文件?????????166??2011-09-15?16:51??4\CLExecutiveCommunication.cpp
?????文件?????????457??2011-09-16?11:19??4\CLExecutiveCommunication.h
?????文件?????????559??2011-09-15?15:28??4\CLExecutiveFunctionForMsgLoop.cpp
?????文件?????????775??2011-09-15?15:06??4\CLExecutiveFunctionForMsgLoop.h
?????文件?????????179??2010-08-12?11:43??4\CLExecutiveFunctionProvider.cpp
?????文件?????????535??2011-08-17?10:00??4\CLExecutiveFunctionProvider.h
?????文件?????????216??2011-09-18?16:50??4\CLExecutiveInitialFinishedNotifier.cpp
?????文件?????????568??2011-09-18?18:29??4\CLExecutiveInitialFinishedNotifier.h
?????文件????????4236??2011-11-05?17:33??4\CLExecutiveNameServer.cpp
?????文件????????1336??2011-11-05?14:31??4\CLExecutiveNameServer.h
?????文件????????2263??2011-09-16?17:24??4\CLLog.cpp
?????文件?????????606??2011-09-04?21:21??4\CLLog.h
?????文件?????????154??2011-09-05?10:59??4\CLMessage.cpp
?????文件?????????449??2011-09-15?10:38??4\CLMessage.h
?????文件????????2839??2011-09-18?21:39??4\CLMessageLoopManager.cpp
?????文件????????1513??2011-09-18?17:52??4\CLMessageLoopManager.h
?????文件?????????127??2011-08-27?13:37??4\CLMessageObserver.cpp
?????文件?????????479??2011-09-15?10:24??4\CLMessageObserver.h
?????文件????????1612??2011-09-19?16:52??4\CLMessageQueue.cpp
?????文件?????????782??2011-09-15?10:11??4\CLMessageQueue.h
?????文件????????1730??2011-09-17?15:59??4\CLMsgLoopManagerForMsgQueue.cpp
?????文件?????????811??2011-09-17?14:13??4\CLMsgLoopManagerForMsgQueue.h
............此處省略16個文件信息
評論
共有 條評論