[Tux4kids-discuss] high cpu usage
deepak aggarwal
deepak.aggarwal9 at gmail.com
Sat Mar 12 10:54:39 UTC 2011
Hi David
When i am working on new server systemthen i encounter a serious problen in
my program that
whenever i run server then either core of my cpu core have 100% usage.
I know this is happening because there is a infinite loop in a thread.
void * main_thread(void * data)
{
int flag=1,choice,n;
int temp;
TCPsocket client_socket,server_socket;
if(!child_intialize_thread())
{
printf("\n There is some error while initializing thread");
return 0;
}
printf("\n Value of active ports is:%d",child_active_ports);
// first server receive request from client to connect and open master
server socket. To be created only once.-permanent
if(common_connect_server(&host_ipaddress,&server_socket,2000,(const char
*)NULL)==0)
return (void *)1;
while(quit)
{
//from here main problem starts i have to keep it in while loop so that it
can accept
if((client_socket=SDLNet_TCP_Accept(server_socket)))
{
// connect to different clients so that it can work as concurrent server. Is
there any way
pthread_mutex_lock(&child_mutex_variable);
// is there any other way to do it and avoid high cpu usage.
printf("\n Value of active ports:%d",child_active_ports);
if(child_active_ports==0)
{
int temp=0;
SDLNet_TCP_Send(client_socket,&(temp),2);
SDLNet_TCP_Close(client_socket);
pthread_mutex_unlock(&child_mutex_variable);
}
else
{
pthread_mutex_unlock(&child_mutex_variable);
printf("\n Activating thread");
activate_thread(client_socket);
}
}
}
printf("\nEverything is OK now exiting");
SDLNet_TCP_Close(server_socket);
cleanup_thread();
return NULL;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/tux4kids-discuss/attachments/20110312/e3fe01fa/attachment.htm>
More information about the Tux4kids-discuss
mailing list