none
WaitForMultipleObjects is hanging on windows 2003 server R2 x64 edition

    Question

  • Hi,

        As part of porting our application from 32bit to 64bit on windows, I have started building our code with Visual Studio 2008.

       I was able to build the existing code successfully without any major changes.

       But when I am running the application I can see that one thread is hanging.

       Following is the scenario:

           a. From main thread we are creating one thread A

           b. This new thread A creates one more thread B.

           c. Thread A does some processing and then waits for Thread B.

           d. For waiting we are using this function.

                 WaitForMultipleObjects(2, wait_hnd, FALSE, INFINITE);

                 Below are the contents of wait_hnd array.

                 wait_hnd[0] = thread->hThread;( Handle to the thread B )
                 wait_hnd[1] = pthread_self_ptr->wait_event; ( Wait event for thread A )

             e. Here I am observing that this function just hangs. And does not return me anything in the code. Even though the thread B is running i am not getting any return value from this function.

         This code works fine on windows 32bit platforms.

        Not sure if because of the windows 64bit platforms, is there any changes in this API.

       I am running my application on windows 2003 server R2 x64 edition.

       If anyone can help me out with this, that will be really great.

       Thanks in advance.

    -Sushil

     

     

    Monday, September 20, 2010 2:33 PM

Answers

All replies

  •        d. For waiting we are using this function.

                 WaitForMultipleObjects(2, wait_hnd, FALSE, INFINITE);

                 Below are the contents of wait_hnd array.

                 wait_hnd[0] = thread->hThread;( Handle to the thread B )
                 wait_hnd[1] = pthread_self_ptr->wait_event; ( Wait event for thread A )

             e. Here I am observing that this function just hangs. And does not return me anything in the code. Even though the thread B is running i am not getting any return value from this function.

    It's supposed to wait until the thread has finished!

    Dave

    Monday, September 20, 2010 3:05 PM
  • I can see that thread B is finising, still this WaitForMultipleObjects is not returning any value to Thread A. Could there be any specific scenario when this can happen?
    Monday, September 20, 2010 4:13 PM
  • You seem to be waiting for thread A to terminate, which means thread A is waiting for itself.  Naturally it will hang.
    Answering policy: see profile.
    Monday, September 20, 2010 4:21 PM
  • If thats the case then I am wondering how this code is working fine on Win32 bit platforms.

    Monday, September 20, 2010 4:37 PM
  • Well, I don't know.  Perhaps I made an assumption which may be clarified by the answers to the following questions:

    Are there only 3 threads involved (A, B and main) ?

    Which thread is calling WaitForMultipleObjects()?

    How is the value of pthread_self_ptr and pthread_self_ptr->wait_event established in your program?

    Can you reproduce this behaviour in a test program?


    Answering policy: see profile.
    Monday, September 20, 2010 5:35 PM
  • Hi David,

    below are the answers to your questions,

    • Are there only 3 threads involved (A, B and main) ?

               Yes in this case we have three threads.

    • Which thread is calling WaitForMultipleObjects()?

              Thread A is calling WaitForMultipleObjects().

    • How is the value of pthread_self_ptr and pthread_self_ptr->wait_event established in your program?

             #define pthread_self_ptr           ((pthread_t)(((PthreadLocal_p_t)TlsGetValue(pthread_global->tls_idx))->self))

             and while creating threads we are making use of this function to create an event object

              ele->wait_event = CreateEvent(NULL, FALSE, FALSE, NULL);

              we do create a mutex object for the thread using

             ele->lock = CreateMutex(NULL, FALSE, NULL);

    Hope this helps.

     

    Tuesday, September 21, 2010 10:45 AM
  • Thanks Guys for your time. I found that there was some issue in the wrapper function on top of these API's. Because of which the running thread was just hanging. I have resolved the issue in my wrapper code. Things are working fine now. -sushil
    Tuesday, September 21, 2010 4:33 PM
  • OK, that answers some questions and raises more.

    I'm going to assume that Thread B's termination is being signalled correctly, which leaves the wait_event in the frame as causing the the problem.

    What signals ele->wait_event?

    Also, your Mutex doesn't seem to be related to the wait_event, based on what you have presented; is there a link, and if so, what is it?

    What is the declaration of ele and how is it shared between the threads?


    Answering policy: see profile.
    Tuesday, September 21, 2010 4:55 PM