Hi David<br>When i am working on new server systemthen i encounter a serious problen in my program that<br>
whenever i run server then either core of my cpu
core have 100% usage.<br>
I know this is happening because there is a infinite loop in a thread.<br>
<br>
void * main_thread(void * data)<br>
{<br>
int flag=1,choice,n;<br>
int temp;<br>
TCPsocket client_socket,server_socket;<br>
if(!child_intialize_thread())<br>
{<br>
printf("\n There is some error while initializing thread");<br>
return 0;<br>
}<br>
printf("\n Value of active ports is:%d",child_active_ports);<br>
<br>
// first server receive request from client to connect and open master server socket. To be created only once.-permanent <br>
if(common_connect_server(&host_ipaddress,&server_socket,2000,(const char *)NULL)==0)<br>
return (void *)1;<br>
while(quit) <br>
{
//from here main problem starts i have to keep it in while loop so that
it can accept <br>
if((client_socket=SDLNet_TCP_Accept(server_socket)))<br>
{
// connect to different clients so that it can work as concurrent
server. Is there any way <br>
pthread_mutex_lock(&child_mutex_variable);
// is there any other way to do it and avoid high cpu usage. <br>
printf("\n Value of active ports:%d",child_active_ports);<br>
if(child_active_ports==0)<br>
{<br>
int temp=0;<br>
SDLNet_TCP_Send(client_socket,&(temp),2);<br>
SDLNet_TCP_Close(client_socket);<br>
pthread_mutex_unlock(&child_mutex_variable);<br>
}<br>
else<br>
{<br>
pthread_mutex_unlock(&child_mutex_variable);<br>
printf("\n Activating thread");<br>
activate_thread(client_socket);<br>
} <br>
}<br>
}<br>
printf("\nEverything is OK now exiting"); <br>
SDLNet_TCP_Close(server_socket);<br>
cleanup_thread();<br>
return NULL;<br>
}<br>