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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Does WaitForSingleObject timeout after 49 days if INFINITE is passed?

Does WaitForSingleObject timeout after 49 days if INFINITE is passed?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 Posters 1 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.
  • P Offline
    P Offline
    PrafullaVedante
    wrote on last edited by
    #1

    We do not know how WaitForSingleObject is implemented. We are just relying on the MSDN documentation. Documentation says, if I pass INFINITE as a timeout value, the function will be blocked indefinitely until the object is signaled. But when I checked the #define value of the INFINITE, it is 0xFFFFFFFF So we pass OxFFFFFFFF to WaitForSingleObject as a timeout. It is equivalent to 49 days. So my question is, does WaitForSingleObject timeout after 49 days if INFINITE is passed. :)

    Prafulla Vedante

    Greg UtasG R CPalliniC 3 Replies Last reply
    0
    • P PrafullaVedante

      We do not know how WaitForSingleObject is implemented. We are just relying on the MSDN documentation. Documentation says, if I pass INFINITE as a timeout value, the function will be blocked indefinitely until the object is signaled. But when I checked the #define value of the INFINITE, it is 0xFFFFFFFF So we pass OxFFFFFFFF to WaitForSingleObject as a timeout. It is equivalent to 49 days. So my question is, does WaitForSingleObject timeout after 49 days if INFINITE is passed. :)

      Prafulla Vedante

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      Without testing it, I'd say it won't time out. Some value has to be used as INFINITE, and the maximum unsigned value is a good choice. Writing the code so that it never expires isn't difficult; it's not like something is going to wake up and decrement it every millisecond.

      Robust Services Core | Software Techniques for Lemmings | Articles

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      1 Reply Last reply
      0
      • P PrafullaVedante

        We do not know how WaitForSingleObject is implemented. We are just relying on the MSDN documentation. Documentation says, if I pass INFINITE as a timeout value, the function will be blocked indefinitely until the object is signaled. But when I checked the #define value of the INFINITE, it is 0xFFFFFFFF So we pass OxFFFFFFFF to WaitForSingleObject as a timeout. It is equivalent to 49 days. So my question is, does WaitForSingleObject timeout after 49 days if INFINITE is passed. :)

        Prafulla Vedante

        R Offline
        R Offline
        RedDk
        wrote on last edited by
        #3

        0xFFFF is a value which is literally NOT "passed". That is, it's something like a zero ("0") used in the BIOS that a user can select/type as input which, under advanced CPU settings for example, signals that "ALL" cores are to be used (say there are 16 cores). Which is not to say that 1, 2, 3, 4, etc cores can take zero's place in the control for the specific input value. It seems contrary to common sense use that a real value can be used to represent a ceiling or a floor as such but when it is the case, generally there's a typed message/note to the substitution next to such a control.

        1 Reply Last reply
        0
        • P PrafullaVedante

          We do not know how WaitForSingleObject is implemented. We are just relying on the MSDN documentation. Documentation says, if I pass INFINITE as a timeout value, the function will be blocked indefinitely until the object is signaled. But when I checked the #define value of the INFINITE, it is 0xFFFFFFFF So we pass OxFFFFFFFF to WaitForSingleObject as a timeout. It is equivalent to 49 days. So my question is, does WaitForSingleObject timeout after 49 days if INFINITE is passed. :)

          Prafulla Vedante

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Quote:

          But when I checked the #define value of the INFINITE, it is 0xFFFF.

          Probably you meant 0xFFFFFFFF. That said, the documentation is clear: if you pass INFINITE (0xFFFFFFFF) then the function shall wait forever (not 2^32-1 milliseconds). So it just depends on how much you trust the documentation.

          In testa che avete, signor di Ceprano?

          P 1 Reply Last reply
          0
          • CPalliniC CPallini

            Quote:

            But when I checked the #define value of the INFINITE, it is 0xFFFF.

            Probably you meant 0xFFFFFFFF. That said, the documentation is clear: if you pass INFINITE (0xFFFFFFFF) then the function shall wait forever (not 2^32-1 milliseconds). So it just depends on how much you trust the documentation.

            P Offline
            P Offline
            PrafullaVedante
            wrote on last edited by
            #5

            You are right 8 Fs are there as it is a 32 bit value.

            Quote:

            So it just depends on how much you trust the documentation. Quote Selected Text

            Yes, As the api source is not open source, Is there any minor possibility of having it blocked for 49 days..... Probably we can check it by debugging the api in assembly code. I am just doubting if microsoft has passed the timeout value to the internal generic logic considering the user will never keep itself block for 49 days .... :rolleyes: :laugh:

            Prafulla Vedante

            CPalliniC J 2 Replies Last reply
            0
            • P PrafullaVedante

              You are right 8 Fs are there as it is a 32 bit value.

              Quote:

              So it just depends on how much you trust the documentation. Quote Selected Text

              Yes, As the api source is not open source, Is there any minor possibility of having it blocked for 49 days..... Probably we can check it by debugging the api in assembly code. I am just doubting if microsoft has passed the timeout value to the internal generic logic considering the user will never keep itself block for 49 days .... :rolleyes: :laugh:

              Prafulla Vedante

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Generally speaking, I trust their documentation.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • P PrafullaVedante

                You are right 8 Fs are there as it is a 32 bit value.

                Quote:

                So it just depends on how much you trust the documentation. Quote Selected Text

                Yes, As the api source is not open source, Is there any minor possibility of having it blocked for 49 days..... Probably we can check it by debugging the api in assembly code. I am just doubting if microsoft has passed the timeout value to the internal generic logic considering the user will never keep itself block for 49 days .... :rolleyes: :laugh:

                Prafulla Vedante

                J Offline
                J Offline
                Joe Woodbury
                wrote on last edited by
                #7

                PrafullaVedante wrote:

                considering the user will never keep itself block for 49 days ....

                I have. Code starts and a section of it waits for a global shutdown object to be signaled. (That aside, I believe Raymond Chen has confirmed that INFINITE really is infinite.)

                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