Hi.
I am writing a Small Server app, which uses TCP/IP. In the classical style, i wait for 'WSAAccept' to unblock, and start a New thread, to process the Client Socket received.
I also use a Structure, to pass information on to the thread function.
Now, the Parent Thread may Loop again (and Modify the Structure to which 'CreateThread' got a pointer before the Thread Function has had a chance to take the values that the Param pointed at.
Below is a Code Snippet.
struct THR_INFO{
CSgSrvrCore* pThis;
SOCKET hSocket;
};
typedef THR_INFO* LP_THR_INFO;
void Class::Function(){
THR_INFO* pThrInfo;
DWORD dwThreadID;
THR_INFO* pThrInfo;
#ifdef PARANOID
pThrInfo=new THR_INFO;
pThrInfo->pThis=this;
pThrInfo->hSocket=h_sockClient;
#else
THR_INFO ThrInfo={this,h_sockClient};
pThrInfo=&ThrInfo;
#endif
CreateThread(0, 0, ConnectToClientThread, pThrInfo, 0, &dwThreadID);
}
void Class::ConnectToClientThread(void* pParam){
LP_THR_INFO pThrInfo=(LP_THR_INFO)p_Param;
SOCKET h_sockClient=pThrInfo->hSocket;
Class* pThis=pThrInfo->pThis;
ASSERT(pThis);
#ifdef PARANOID
delete p_Param;
#endif
}
Should I not be PARANOIDE, and the basic function will be thead safe, or should I include further Synchronisation Objects.
Regards :)