Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WaitForMultipleObjects keeps catching timeout event (RESOLVED)

WaitForMultipleObjects keeps catching timeout event (RESOLVED)

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiocomhelp
4 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bkelly13
    wrote on last edited by
    #1

    Windows 7, 64 bit, Visual Studio 2012, MFC, C++ Summary: The app starts a new thread and waits on multiple events from the main to do something. The wait specifies no timeout. At this point, the main has not created any events. Within the thread the case statement shows a timeout is always present. I tried resetting the time out event but get the error code invalid handle. What did I do wrong to cause the timeout event and what must be changed to stop it. Details: The following is phrases extracted from the thread code:

    const BOOL WAIT_FOR_ANY_EVENT = FALSE;
    const BOOL WAIT_FOR_ALL_EVENTS = TRUE;
    const DWORD WAIT_TIMEOUT_VALUE = 5000;
    const DWORD NO_TIMEOUT = 0;
    ...
    event_detected = WaitForMultipleObjects(
    EVENT_ARRAY_SIZE,
    mp_common_data->event_array,
    WAIT_FOR_ANY_EVENT,
    NO_TIMEOUT );
    ...
    switch( event_detected )
    {
    case WAIT_TIMEOUT: // defined in winerror.h, value = 258L
    {
    mp_common_data->count_of_timeout_events ++;
    BOOL reset_status = ResetEvent( (HANDLE ) WAIT_TIMEOUT );
    if( reset_status == FALSE )
    {
    m_wsa_error = GetLastError(); // error = 6, invalid handle
    }
    ...
    break;
    }
    ...
    }

    Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

    S 1 Reply Last reply
    0
    • B bkelly13

      Windows 7, 64 bit, Visual Studio 2012, MFC, C++ Summary: The app starts a new thread and waits on multiple events from the main to do something. The wait specifies no timeout. At this point, the main has not created any events. Within the thread the case statement shows a timeout is always present. I tried resetting the time out event but get the error code invalid handle. What did I do wrong to cause the timeout event and what must be changed to stop it. Details: The following is phrases extracted from the thread code:

      const BOOL WAIT_FOR_ANY_EVENT = FALSE;
      const BOOL WAIT_FOR_ALL_EVENTS = TRUE;
      const DWORD WAIT_TIMEOUT_VALUE = 5000;
      const DWORD NO_TIMEOUT = 0;
      ...
      event_detected = WaitForMultipleObjects(
      EVENT_ARRAY_SIZE,
      mp_common_data->event_array,
      WAIT_FOR_ANY_EVENT,
      NO_TIMEOUT );
      ...
      switch( event_detected )
      {
      case WAIT_TIMEOUT: // defined in winerror.h, value = 258L
      {
      mp_common_data->count_of_timeout_events ++;
      BOOL reset_status = ResetEvent( (HANDLE ) WAIT_TIMEOUT );
      if( reset_status == FALSE )
      {
      m_wsa_error = GetLastError(); // error = 6, invalid handle
      }
      ...
      break;
      }
      ...
      }

      Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

      S Offline
      S Offline
      SoMad
      wrote on last edited by
      #2

      I don't see a problem with WaitForMultipleObjects()[^] returning WAIT_TIMEOUT in this case. The documentation states:

      Quote:

      WAIT_TIMEOUT: The time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied.

      Even though you are specifying zero as your time-out interval, it is still an interval (sort of). Look at the documented return values and think about what other value could be returned in this case. If your intention is to wait until your events actually signal, then consider using INFINITE instead of zero, but beware of the problems that might cause - you will be waiting until all events in your array are signaled. BTW, are you sure you want to specify bWaitAll = TRUE? Bear in mind, that this is AND logic, meaning all of your events must be signaled before WaitForMultipleObjects() returns a non-error result. The ResetEvent()[^] returns FALSE because you are not passing a valid handle. You pass in a timeout value, but that is not how that function is used. Soren Madsen

      "When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty

      B 1 Reply Last reply
      0
      • S SoMad

        I don't see a problem with WaitForMultipleObjects()[^] returning WAIT_TIMEOUT in this case. The documentation states:

        Quote:

        WAIT_TIMEOUT: The time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied.

        Even though you are specifying zero as your time-out interval, it is still an interval (sort of). Look at the documented return values and think about what other value could be returned in this case. If your intention is to wait until your events actually signal, then consider using INFINITE instead of zero, but beware of the problems that might cause - you will be waiting until all events in your array are signaled. BTW, are you sure you want to specify bWaitAll = TRUE? Bear in mind, that this is AND logic, meaning all of your events must be signaled before WaitForMultipleObjects() returns a non-error result. The ResetEvent()[^] returns FALSE because you are not passing a valid handle. You pass in a timeout value, but that is not how that function is used. Soren Madsen

        "When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty

        B Offline
        B Offline
        bkelly13
        wrote on last edited by
        #3

        I have the answer. Wait 0 in most places, all that I have used until now, means no wait period. In this case it means immediately time out. I should have read the documentation more carefully. Still, that is not a good option to have. Argument 3 is wait for any event, not wait for all. This is still in the initial stages of testing, just getting the events right and not doing anything useful. (Then again, that test is quite useful.) To help me in the future I changed my time out constants as follows:

        // "INFINITE" is defined by Microsoft and is a valid timeout value
        const DWORD WAIT_TIMEOUT_05_SECONDS = 5000;
        const DWORD WAIT_TIMEOUT_60_SECONDS = 60000;
        const DWORD IMMEDIATE_TIMEOUT = 0;

        Thank you for the re-direct.

        Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

        S 1 Reply Last reply
        0
        • B bkelly13

          I have the answer. Wait 0 in most places, all that I have used until now, means no wait period. In this case it means immediately time out. I should have read the documentation more carefully. Still, that is not a good option to have. Argument 3 is wait for any event, not wait for all. This is still in the initial stages of testing, just getting the events right and not doing anything useful. (Then again, that test is quite useful.) To help me in the future I changed my time out constants as follows:

          // "INFINITE" is defined by Microsoft and is a valid timeout value
          const DWORD WAIT_TIMEOUT_05_SECONDS = 5000;
          const DWORD WAIT_TIMEOUT_60_SECONDS = 60000;
          const DWORD IMMEDIATE_TIMEOUT = 0;

          Thank you for the re-direct.

          Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

          S Offline
          S Offline
          SoMad
          wrote on last edited by
          #4

          bkelly13 wrote:

          Argument 3 is wait for any event, not wait for all.

          My bad, I could have sworn you were passing in the constant defined as TRUE there. Soren Madsen

          "When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups