...
struct thread_func_args
{
CTCPComm_Process pThis;
unsigned int arg;
thread_func_args (CTCPComm_Process t,unsigned int p)
: pThis(t),arg(p){}
};
unsigned int socket_array[MAX_SOCKET];
...
....
CTCPComm_Process tcp_proc;
tcp_proc.m_nLsnSocketHandle=&m_nLsnSocketHandle;
#ifndef WIN32
pthread_mutex_lock(&mutex);
socket_array[nConnection_Count++]=client_sockfd; //client_sockfd는 소켓통신시 accept로 받은 소켓 핸들 값 이게 뒤에 인자로 전달...
thread_func_args pthread_args(tcp_proc,socket_array[nConnection_Count-1]);
LOG4CPLUS_INFO(logger,"Current Thread Cnt " << socket_array[nConnection_Count-1]);
pthread_mutex_unlock(&mutex);
#endif
LOG4CPLUS_INFO(logger,"Current Thread Cnt " << pthread_args.arg);
status = pthread_create(&hThread,
NULL,
&CTCPComm::ValidateData_Client,
&pthread_args);
if (status!=0){
LOG4CPLUS_ERROR(logger, "CTCPComm::Client pthread_create 실패 nRtnValue = " << status);
close(client_sockfd);
client_sockfd=-1;
}
pthread_detach( hThread ); //이걸 안하면 메모리 릭이 발생함
...
/*ValidateData_Client ==> static이어야 한다.*/
void* CTCPComm::ValidateData_Client(void* Parameter)
#endif
{
thread_func_args* tf_args=static_cast<thread_func_args*>(Parameter);
CTCPComm_Process pLocalThis=tf_args->pThis;
pLocalThis.ValidateCall(tf_args->arg);
delete tf_args;
pthread_exit((void *)NULL);
}