Original Post
OK
I have my program spawning threads as usual but for some reason it seems to be only executing one of the threads (no matter how many I spawn.
The thread function is similar to this at this point.
Thanks for any help,
Webby
LocalSend()
{
while(bKeepAlive == true)
{
cout << "In LocalSend()";
cout << GetCurrentProcessId() << endl;
Sleep(1000);
}
LocalRecv()
{
while(bKeepAlive == true)
{
cout << "In LocalSend()";
cout << GetCurrentProcessId() << endl;
Sleep(1000);
}
The main program defines and object and passes in the number of each thread to create. The threads are getting created correctly with unique HANDLES/threadIDs. I check the handles just after I create the threads and before pushing the handles
onto a vector for keeping.
However, when I execute the code it keeps outputting the HANDLE/ID of the same thread over and over.
Here is how I am creating my threads:
StartThreads(int iNumRecvThreads, int iNumSendThreads)
{
int iThreadCount;
HANDLE hThreadHandle;
DWORD dwThreadID;
//cBaseServer* pRecv = NULL;
//cBaseServer* pSend = NULL;
for (iThreadCount=0; iThreadCount < iNumRecvThreads;
iThreadCount++)
{
hThreadHandle = CreateThread(NULL, NULL,
RecvDispatch,
reinterpret_cast< LPVOID >(this),
NULL, &dwThreadID);
if (hThreadHandle == NULL)
{
perror("Recieve Thread Creation Problem");
exit(1);
}
vRecvThreadPool.push_back(hThreadHandle);
}
for (iThreadCount=0; iThreadCount < iNumSendThreads;
iThreadCount++)
{
hThreadHandle = CreateThread(NULL, NULL,
SendDispatch, reinterpret_cast< LPVOID >(this), NULL, &dwThreadID);
if (hThreadHandle == NULL)
{
perror("Recieve Thread Creation Problem");
exit(1);
}
vSendThreadPool.push_back(hThreadHandle);
}
}
I might be mistaken but isn''t Sleep(xxx) supposed to put that specific thread to sleep for the given milliseconds thus allowing other threads to use the processor?
It''s something trivial I know, but I can''t pick it out