A Strange Error from Multithreading Socket - Help!
Posted on 2000-03-27
I've got a strange error from my project that is using CSocket with multithread.
The following code from my server project is same as what is described in MSDN:
In function OnAccept for the listening socket:
void CListensoc::OnAccept(int nErrorCode)
// New connection is being established
// Accept the connection using a temp CSocket object.
// Create a thread to handle the connection.
// The thread is created suspended so that we can
// set variables in CConnectThread before it starts executing.
CConnectThread* pThread = (CConnectThread*)
// Pass the socket to the thread by passing the socket handle.
// You cannot pass a CSocket object across threads.
pThread->m_hSocket = soc.Detach();
// Now start the thread.
And then I have the following code in function InitInstance of the class CConnectThread:
m_Socket.Attach(m_hSocket); // THIS CODE CAUSE A ACCESS VOILATION ERROR!
BUT I've got a strange access violation error at the line m_socket.Attach(m_hSocket).
Debugging shows the error came from a function in MAP_PP.CPP of MFC:
void* CMapPtrToPtr::GetValueAt(void* key) const
// find value (or return NULL -- NULL values not different as a result)
if (m_pHashTable == NULL) // m_pHashTable is NULL!
Could anybody tell me why and how to solve the problem?
Thanks in advance!