简体   繁体   中英

forcefully return from a method that called from a thread if thread itself exited

I have used one pthread for polling network every 2 secs. For this I am calling one Client Interface from run() method of pthread. But what is happening when network is down between server and client this method should throw exception, but this is not happening right now.So what I planning is to forcefully return this method and exit the thread.

To achieve this I have tried to forcefully exit from thread by signaling it. But the problem I am still facing is that after exitting from thread itself client inteface is throwing exception very late.This leading to inconsistent behaviour in my implementation.

My code looks like this

//server side code
//This is Linux code

void ServerImp::run()
{
  try {
  while(1)
  {
    Client->PingNetwork()
  }
  }
  catch(...)
  {
    //Handle exception
  }

}

//PingNetwork implementation
//This is Windows code
void NetworkImpl::PingNetwork() throw exception
{
  try{
  while(IsValidClient())//This will return as soon as client disconnected from server
  {
     sleep(2);
  }
  }
  catch(...)
  {
     //Handle exception
  }
}

Basic idea to ask this question is that for me my underlying interace TAO 2.0a is not detecting network failure immediately for current session but on client side it detect it well in time and initiate one more new session for connection.But after sometime both new and old session got CORBA::COMM_FAILURE exception so it leading to unstable behaviour in server and client. Is that something TAO limitation? or I have to do something to make it work. Please help me out if is there any way to work around here.

Thanks

It sounds like your force exited thread is not exited cleanly. A cleanly exited thread should have all its context destroyed and not leaving any residue. The pthread can be either joinable or detached, which type of thread creation you use? After your force exit happen, does your "Client" object destroyed? What about the logic that creates the thread, does it handle exception of a zombie thread? Answer all theses question yourself and handles all these details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM