dwu
July 11th, 2005, 10:30 AM
I created a c++ multithread ATL DLL, and each thread will call a component written with VB6 to do a stored procedure call. I found there is no different in performance between a single thread and multithread. Help!
Trace time in thread like this:
1 Thread
vb function call time: 109
c++ other code time: 62
2 thread
vb function call time: 156
c++ other code time: 62
3 thread
vb function call time: 256
c++ other code time: 62
and VB component log time:
1 Thread
vb function call time: 109
c++ code time: 62
2 thread
vb function call time: 109
C++ code time: 110
3 thread
vb function time: 109
c++ code time: 219
C++ code like this:
unsigned _stdcall CMTTest::DoVBFunction(LPVOID pThis)
{
CMTWrapper* pThisObject = static_cast<CMTTest*>(pThis);
HRESULT hr=S_OK;
DWORD dwLastStart = GetTickCount();
DWORD dwCount;// = GetTickCount();
CComPtr<_DMTTest> pServer;
hr=pServer.CoCreateInstance (pThisObject->mszServerProgID);
for (;;) {
if (WAIT_OBJECT_0 == WaitForSingleObject(pThisObject->mhParamMutex ,50)){
bDoJob = !(pThisObject->mParamQueue.empty());
dwMyId = ::GetCurrentThreadId();
pMap = pThisObject->mThreadsWorking.find(dwMyId);
if (pMap == pThisObject->mThreadsWorking.end()) {
ReleaseMutex(pThisObject->mhParamMutex);
pThisObject->Fire_ServerFuncDone(FATAL_SERVER_ERROR);
return -1;
}
pMap->second = bDoJob;
ReleaseMutex(pThisObject->mhParamMutex);
}
else
bDoJob = FALSE;
if (bDoJob) {
dwCount=GetTickCount() - dwLastStart;
dwLastStart=GetTickCount();
AtlTrace(_T("Thread: %d, C++ code Time: %d.\n"),dwMyId, dwCount);
hr = pServer->raw_ServerFunc (dwMyId,&nReturn,&pvParam);
dwCount=GetTickCount() - dwLastStart;
dwLastStart=GetTickCount();
AtlTrace(_T("Thread: %d, VB function call Time: %d.\n"),dwMyId, dwCount);
}
if (WAIT_OBJECT_0 == WaitForSingleObject(pThisObject->mhTimeToDie,50))
{
return 0;
}
}
return 0;
}
Thanks.
David
Trace time in thread like this:
1 Thread
vb function call time: 109
c++ other code time: 62
2 thread
vb function call time: 156
c++ other code time: 62
3 thread
vb function call time: 256
c++ other code time: 62
and VB component log time:
1 Thread
vb function call time: 109
c++ code time: 62
2 thread
vb function call time: 109
C++ code time: 110
3 thread
vb function time: 109
c++ code time: 219
C++ code like this:
unsigned _stdcall CMTTest::DoVBFunction(LPVOID pThis)
{
CMTWrapper* pThisObject = static_cast<CMTTest*>(pThis);
HRESULT hr=S_OK;
DWORD dwLastStart = GetTickCount();
DWORD dwCount;// = GetTickCount();
CComPtr<_DMTTest> pServer;
hr=pServer.CoCreateInstance (pThisObject->mszServerProgID);
for (;;) {
if (WAIT_OBJECT_0 == WaitForSingleObject(pThisObject->mhParamMutex ,50)){
bDoJob = !(pThisObject->mParamQueue.empty());
dwMyId = ::GetCurrentThreadId();
pMap = pThisObject->mThreadsWorking.find(dwMyId);
if (pMap == pThisObject->mThreadsWorking.end()) {
ReleaseMutex(pThisObject->mhParamMutex);
pThisObject->Fire_ServerFuncDone(FATAL_SERVER_ERROR);
return -1;
}
pMap->second = bDoJob;
ReleaseMutex(pThisObject->mhParamMutex);
}
else
bDoJob = FALSE;
if (bDoJob) {
dwCount=GetTickCount() - dwLastStart;
dwLastStart=GetTickCount();
AtlTrace(_T("Thread: %d, C++ code Time: %d.\n"),dwMyId, dwCount);
hr = pServer->raw_ServerFunc (dwMyId,&nReturn,&pvParam);
dwCount=GetTickCount() - dwLastStart;
dwLastStart=GetTickCount();
AtlTrace(_T("Thread: %d, VB function call Time: %d.\n"),dwMyId, dwCount);
}
if (WAIT_OBJECT_0 == WaitForSingleObject(pThisObject->mhTimeToDie,50))
{
return 0;
}
}
return 0;
}
Thanks.
David