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


OS : Windows XP
Compiler : VC++ 6.0
pthreads library :

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_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 */      

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

            if (count < 0 && errno != EINVAL)
                           // Error Handling

            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;
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.
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.