HyperEngineer
Programmer
I have a DLL that has one class that instantiates two other classes that use BeginThread(). It seems that the two new threads just stop processing. Here is some of the code.
The calling class:
This instantiates the classes:
This sets the m_bStartSession flag monitored in the first class:
First called class:
This is in the constructor:
This is in the new thread RdTh():
Second called class:
This is in the constructor:
This is in the new thread SendTh();
The two while loops in RED execute once. Where do they go after that? They don't continue with the routine and they don't execute the loop any more.
Thanks for the help.
HyperEngineer
If it ain't broke, it probably needs improvement.
The calling class:
This instantiates the classes:
Code:
msg = (char*) malloc(128);
sprintf(msg, "Socket = %d\n", m_hSocket);
WriteToLogFile(msg);
// Start the Rx & Tx threads[b]
CSocketRx m_SocketRx((void*) this);
CSocketTx m_SocketTx((void*) this);[/b]
sprintf(msg, "Rx and Tx sockets created\n");
WriteToLogFile(msg);
free(msg);
Code:
msg = (char*) malloc(128);
sprintf(msg, "Set start session flag = %d\n", g_TelnetPipe->m_bStartSession);
WriteToLogFile(msg);
[b]
g_TelnetPipe->m_bStartSession = true;
[/b]
sprintf(msg, "Wait for log in\nSession flag = %d\n", g_TelnetPipe->m_bStartSession);
WriteToLogFile(msg);
This is in the constructor:
Code:
sprintf(msg, "Start receive thread\n");
WriteToLogFileRx(msg, hLogFileRx);[b]
m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) RdTh,(LPVOID)this,0,&dwRet);[/b]
Sleep(100);
sprintf(msg, "Rx Thread = %d\n", m_hThread);
WriteToLogFileRx(msg, hLogFileRx);
sprintf(msg, "Start receive thread\n");
WriteToLogFileRx(msg, hLogFileRx);
m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) RdTh,(LPVOID)this,0,&dwRet);
Sleep(100);
sprintf(msg, "Rx Thread = %d\n", m_hThread);
WriteToLogFileRx(msg, hLogFileRx);
Code:
sprintf(msg, "Waiting for start session flag for %s\n", g_TelnetPipe->m_cIP);
WriteToLogFileRx(msg, pSocketRx->m_hLogFileRx);
// Can't go anywhere until the main thread is ready.[b][COLOR=red]
while(!(g_TelnetPipe->m_bStartSession)) // This loop executes once then.....
{
iRet = IdleFunctionRx();
Sleep(200);
WriteToLogFileRx("Rx waiting", pSocketRx->m_hLogFileRx);
}[/color][/b]
// Program never gets this far
sprintf(msg, "Start session\n");
WriteToLogFileRx(msg, pSocketRx->m_hLogFileRx);
This is in the constructor:
Code:
sprintf(msg, "Start transmit thread\n");
WriteToLogFileTx(msg, hLogFileTx);[b]
m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) SendTh,(LPVOID)this,0,&dwRet);[/b]
Sleep(100);
sprintf(msg, "Tx Thead - %ld\n", m_hThread);
WriteToLogFileTx(msg, hLogFileTx);
Code:
sprintf(msg, "Waiting for send request\n");
WriteToLogFileTx(msg, pSocketTx->m_hLogFileTx);[b][COLOR=red]
while(!g_TelnetPipe->m_bSendRequest) // executes once..
{
nRet = IdleFunctionTx();
Sleep(100);
WriteToLogFileTx("Tx waiting", pSocketTx->m_hLogFileTx);
}[/color][/b]
// Program does not get this far.
g_TelnetPipe->m_bSendRequest = false;
sprintf(msg, "Send command = %s\n", g_TelnetPipe->m_cSendCommand);
WriteToLogFileTx(msg, pSocketTx->m_hLogFileTx);
Thanks for the help.
HyperEngineer
If it ain't broke, it probably needs improvement.