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;
}
k_kalyanAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
There are number of calls inside of thread: select, recv, FD_CLR etc. Are these calls blocking? When thread must exit, every call inside of this thread should return immediately.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.