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

Posted on 2006-06-02
Last Modified: 2013-11-15

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;
Question by:k_kalyan
    1 Comment
    LVL 48

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    C++ to C# code conversion issue 4 73
    Visual xHarbour 1 48
    URL to download Windows 10 Home 2 69
    Peachtree 2012 Help 2 27
    Article by: Rob
    Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    Introduction to GIMP:  GNU Image Manipulation Program. It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now