Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
happy new Year for every body :)
iam sorry for posting this question in this day but iam need to solve it
i develop on unix service using c++ and problem is thread A1 in it that start from parent thread A and the A1 start other thread B1 then A1 terminate and B1 handle the request if i open lot of session threads that connect to test
C#
pid =   fork();
    while(true)
    {

            s = accept(Socket,(struct sockaddr*)&client,&len);

            if( s >-1)
                {


                printf("\n other client port %i\n",client.sin_port);

                printf("\n client connected address %s \n",inet_ntoa(client.sin_addr));


                re = new HandleResponse(); // this thread in create state not running 

                              //  r is  CircularResponse();


                re->set_Client(s);

                        re->set_manager(share_manager);


                              r->addClient(re); // add here 

                               r->start(); // and start it parent 

                     printf("\n process accept \n");

                }
            else
            {
                printf("\n wait error connecting \n");
            }


    }


and CircularResponse() is
C++
void CircularResponse::addClient(HandleResponse *r)
{
   qclient->push_back(r);
}
void *CircularResponse::run()
{
    HandleResponse *current;
//  HandleResponse * del;
    int h = 1;
    printf("handle Response Thread");
//    pid_t pid = fork();
printf("\n Circular response \n");

  while(true)
  {
      if(!qclient->empty())
       {
              current = qclient->front();




                        h = current->check_connect();
        printf(" current->check_connect() %i \n",h);
  printf(" thread %lu \n",current->self());
          if(h==-1)
          {


               printf("\n here I kill thread %lu \n",current->self());
               qclient->erase(std::remove(qclient->begin(),qclient->end(),current));
                delete current;
               // free(current);

                 if(qclient->size()==0)
                 {
                 printf("qclient is empty %i",qclient->size());
               //break;
              }
          }

            current->start();
             // qclient->push_back(current);
               //      current->join();
                 //    printf("join");




       printf("\n client connected %i \n",(int)qclient->size());
        qclient->pop_front();
   }
   sleep(3);
  }
  printf("\n LTSC_Manager Finsh Job  \n");
  return NULL;


and handle response is
C#
int HandleResponse::ProcessResponse()
{
     int h =0;
     printf("\n Read thread %lu \n",this->m_tid);
     string Technology = "",Exchange = "",Switch = "" ;

            h = read(Socket,&bbuf,sizeof(bbuf));

            if(h == 0 )
            {

                printf("\n  other Client Close \n");
                close(Socket);
                Socket = -1;
                pthread_cancel(this->m_tid);
                printf("\n done \n");
                return -1;

            }


            IDriver * driver = NULL ;

            CComponentsKernel* g = new CComponentsKernel();

            IComponent* comp = g->CreateComponent("TL1 Parser");

            vector<CParserOutNode> m_Param;

            char *TestType = NULL;

            map<string,string> m_Tl1ParamsMap;

            if(comp)
....
....



so problem is sometimes the last two thread go to zombie state is this design pattern is true or not or there are error in design hint this is all inherit form pthread class
Posted
Comments
Pablo Aliskevicius 1-Jan-15 4:43am    
Take a look at this:
http://programmers.stackexchange.com/questions/164039/what-is-a-zombie-process-or-thread

1 solution

in your while(true) loops should be some exit logic. Some proper stuff: global memory, event or handle. Choose best.

And you should control the amount of open threads to balance the resource usage.
 
Share this answer
 
Comments
Mahmoud_Gamal 1-Jan-15 15:57pm    
your solution is logic and i will do it but there are service that connect to this all time with no limit need all to handle

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900