Link to home
Start Free TrialLog in
Avatar of k_kalyan
k_kalyan

asked on

VC++ 6.0 : pthread_join is hanging (Linux to Windows porting)

Hello,

OS : Windows XP
Compiler : VC++ 6.0
pthreads library : http://sources.redhat.com/pthreads-win32/

In the following sample program, pthread_join is hanging in Windows and same is working in Linux.

Could u please explain why pthread_join is hanging here though the cancellation point is enabled.

What are all the possible causes for pthread_join to hang ?

============================================================

// Thread Creation -- finish the job -- and Join thread to the main thread
--------------------------------------------------------------------------------------
Sdf_fn_createThread (&(this->dnsProcessResultsThreadId), Sdf_co_null,                                                                                       dnsResultProcessorThread,\
                                        (void*)this, &error));

pthread_cancel(this->dnsProcessResultsThreadId);
pthread_join(this->dnsProcessResultsThreadId, &pExitCode); // Hanging ?

--------------------------------------------------------------------------------------      

void* dnsResultProcessorThread ( void *pData) // Actual Job of the thread
{
      fdset      read_fds, write_fds;
      int nfds,count;
      timeVal *tvp,tv;
      
      /* Cancel enable the thread */
      pthread_setcancelstate(Sdf_mc_cancelEnable, Sdf_co_null);
      
      while (1)
      {
            /* Check if the thread is cancelled */      
            pthread_testcancel();

            FD_ZERO(&read_fds);
            FD_ZERO(&write_fds);
            
            /* wait for arrival of data , or a timeout to occur*/
            count = select(nfds, &read_fds, &write_fds, NULL, tvp);
            pthread_testcancel();

            if (count < 0 && errno != EINVAL)
            {
                           // Error Handling
                  continue;
            }

            if(FD_ISSET(pLookupDns->sockfd, &read_fds) != 0)
                  
            {
                  /* Indicates that a new query is made.*/
                  FD_CLR(pLookupDns->sockfd, &read_fds);
                  char buf[9];
                  count = recv(pLookupDns->sockfd,buf,9,0);
                }
      }
      return NULL;
}
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial