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 anything affect Sleep ()

Does anything affect Sleep ()

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

    If a computer is suspended/hibernating, does that affect then length of time a process will sleep for? If a process is told to Sleep () for 1 hour and after half an hour the computer is put into hibernate for 2 hours, when it starts back up again and Windows resumes, does the process still have half an hour to Sleep (), or is its Sleep () time up (having effectively slept for 2 1/2 hours already)?

    T R 2 Replies Last reply
    0
    • C cheesepirate

      If a computer is suspended/hibernating, does that affect then length of time a process will sleep for? If a process is told to Sleep () for 1 hour and after half an hour the computer is put into hibernate for 2 hours, when it starts back up again and Windows resumes, does the process still have half an hour to Sleep (), or is its Sleep () time up (having effectively slept for 2 1/2 hours already)?

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      i don't know for your effective question, but don't use sleep() function for so long waits... i uses active waits, and so need full CPU time.


      TOXCCT >>> GEII power

      C J 2 Replies Last reply
      0
      • C cheesepirate

        If a computer is suspended/hibernating, does that affect then length of time a process will sleep for? If a process is told to Sleep () for 1 hour and after half an hour the computer is put into hibernate for 2 hours, when it starts back up again and Windows resumes, does the process still have half an hour to Sleep (), or is its Sleep () time up (having effectively slept for 2 1/2 hours already)?

        R Offline
        R Offline
        Rafael Fernandez Lopez
        wrote on last edited by
        #3

        Well.. TEST IT !! ;P You can send a MessageBox after the Sleep() function, so if you start back up again and the message is on your screen it means that it worked. I think is the best option... ;)


        Written by: Rafael Fernández López.

        Visit: http://www.maestroprogramador.com

        C 1 Reply Last reply
        0
        • R Rafael Fernandez Lopez

          Well.. TEST IT !! ;P You can send a MessageBox after the Sleep() function, so if you start back up again and the message is on your screen it means that it worked. I think is the best option... ;)


          Written by: Rafael Fernández López.

          Visit: http://www.maestroprogramador.com

          C Offline
          C Offline
          cheesepirate
          wrote on last edited by
          #4

          I'm inclined to agree - just I got an attack of lazyitis and didn't want to hibernate a pc :)

          1 Reply Last reply
          0
          • T toxcct

            i don't know for your effective question, but don't use sleep() function for so long waits... i uses active waits, and so need full CPU time.


            TOXCCT >>> GEII power

            C Offline
            C Offline
            cheesepirate
            wrote on last edited by
            #5

            Yeah, it's not good - I got a program dropped on my desk and while I'm fixing it by re-writing it, I still have to try and make the old version work :(

            1 Reply Last reply
            0
            • T toxcct

              i don't know for your effective question, but don't use sleep() function for so long waits... i uses active waits, and so need full CPU time.


              TOXCCT >>> GEII power

              J Offline
              J Offline
              Jens Doose
              wrote on last edited by
              #6

              I am not quite sure if Sleep really waits actively... See MSDN: The Sleep function suspends the execution of the current thread for at least the specified interval. Jens

              T 1 Reply Last reply
              0
              • J Jens Doose

                I am not quite sure if Sleep really waits actively... See MSDN: The Sleep function suspends the execution of the current thread for at least the specified interval. Jens

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                yes, what does it say with that ??! give us the entire paragraph please... :-D i already read the MSDN ; it is not advised


                TOXCCT >>> GEII power

                J 1 Reply Last reply
                0
                • T toxcct

                  yes, what does it say with that ??! give us the entire paragraph please... :-D i already read the MSDN ; it is not advised


                  TOXCCT >>> GEII power

                  J Offline
                  J Offline
                  Jens Doose
                  wrote on last edited by
                  #8

                  My comment didn't answer your original question. I just wanted to state that I don't think that calling "Sleep" will cause the thread to wait actively. It would be rather dumb to implement a task scheduler which lets a thread that called Sleep wait actively, wouldn't it? To clarify: By "waiting actively" I mean a continous loop until a condition is reached, like this one: while ( true ) { if ( bConditionIsReached ) { break; } } Jens

                  T 1 Reply Last reply
                  0
                  • J Jens Doose

                    My comment didn't answer your original question. I just wanted to state that I don't think that calling "Sleep" will cause the thread to wait actively. It would be rather dumb to implement a task scheduler which lets a thread that called Sleep wait actively, wouldn't it? To clarify: By "waiting actively" I mean a continous loop until a condition is reached, like this one: while ( true ) { if ( bConditionIsReached ) { break; } } Jens

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    yes, i understood what your previous post said about this, and i know what is an active wait. just paste here what MSDN say about sleep() (but give the entire text on it).


                    TOXCCT >>> GEII power

                    J 1 Reply Last reply
                    0
                    • T toxcct

                      yes, i understood what your previous post said about this, and i know what is an active wait. just paste here what MSDN say about sleep() (but give the entire text on it).


                      TOXCCT >>> GEII power

                      J Offline
                      J Offline
                      Jens Doose
                      wrote on last edited by
                      #10

                      See here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sleep.asp Jens

                      T 1 Reply Last reply
                      0
                      • J Jens Doose

                        See here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sleep.asp Jens

                        T Offline
                        T Offline
                        toxcct
                        wrote on last edited by
                        #11

                        well, you didn't want to copy the text, i give you : If you have a thread that uses Sleep with infinite delay, the system will deadlock. How do you understand this ???? ;P


                        TOXCCT >>> GEII power

                        J 1 Reply Last reply
                        0
                        • T toxcct

                          well, you didn't want to copy the text, i give you : If you have a thread that uses Sleep with infinite delay, the system will deadlock. How do you understand this ???? ;P


                          TOXCCT >>> GEII power

                          J Offline
                          J Offline
                          Jens Doose
                          wrote on last edited by
                          #12

                          Well the context of this sentence deals with messages, and if you read a little bit more it reads Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang. But I don't see this as an evidence that Sleep waits actively. Jens

                          T T 2 Replies Last reply
                          0
                          • J Jens Doose

                            Well the context of this sentence deals with messages, and if you read a little bit more it reads Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang. But I don't see this as an evidence that Sleep waits actively. Jens

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #13

                            no messages are advised ! do you read entierely the particle or you only see some word ?! MSDN says that if you have to create a nex thread, you mustn't use sleep() because of this problem.


                            TOXCCT >>> GEII power

                            1 Reply Last reply
                            0
                            • J Jens Doose

                              Well the context of this sentence deals with messages, and if you read a little bit more it reads Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang. But I don't see this as an evidence that Sleep waits actively. Jens

                              T Offline
                              T Offline
                              Toby Opferman
                              wrote on last edited by
                              #14

                              The system will only deadlock if a message is sent to a window that is on a thread using "Sleep" in a non-alertable state. If you use "SleepEx", the second parameter allows the thread to wait in an "alertable" state. A "SendMessage" queues an APC on the window's thread and will be processed if the thread is in an "alertable" state. So, if you use SleepEx() and maintain an alertable thread state you will be able to become signaled. Sleep() is also a system call. It's not implemented in user-mode, so it doesn't do a while(x < 10). It's not a spinlock either. The thread should be delayed in the scheduler until the sleep has expired. I'm not sure what the original question was, but it was something about going into a hibernate state. Perhaps this should answer the question (Link Below) If this is true, I would think that the thread sleep would continue to sleep once the machine resumed, since it technically hasn't slept the full period. The only way it wouldn't is unless the scheduler bases the sleep off of time (Which would have changed) and it processes this information upon restart. Of course, even if it is based off of time, generally the OS is probably notified of a hibernation and it could make special arrangements to honor the full sleep independent of the hibernation, ie, resume after the system restarted. I can't be sure of that without a test. You could write a thread to sleep and after the sleep write a debug message or something. Perform the test and verify the results. Though, generally speaking, the results could vary by implementation (hardware, OS, etc.) but most likely the implementations should match what you find. http://www.veritest.com/benchmarks/battmark/bb3power\_man/b3sleep.asp Hibernation Hibernation is one of several terms describing a state of reduced power consumption that a power-managed computer may support. According to the conventional definition of hibernation, a notebook copies all memory contents and hardware state information to non-volatile storage (typically the hard disk, which requires no power to retain information), and the notebook is completely powered down. Leaving hibernation and returning the system to full operation requires booting the computer as usual and then waiting while the system restores the memory contents and hardware state. The process is finished when the computer is at exactly the point it was when the hibernate process started. Hibernation trades time for power: maintaining the system state requires no power (beca

                              T 1 Reply Last reply
                              0
                              • T Toby Opferman

                                The system will only deadlock if a message is sent to a window that is on a thread using "Sleep" in a non-alertable state. If you use "SleepEx", the second parameter allows the thread to wait in an "alertable" state. A "SendMessage" queues an APC on the window's thread and will be processed if the thread is in an "alertable" state. So, if you use SleepEx() and maintain an alertable thread state you will be able to become signaled. Sleep() is also a system call. It's not implemented in user-mode, so it doesn't do a while(x < 10). It's not a spinlock either. The thread should be delayed in the scheduler until the sleep has expired. I'm not sure what the original question was, but it was something about going into a hibernate state. Perhaps this should answer the question (Link Below) If this is true, I would think that the thread sleep would continue to sleep once the machine resumed, since it technically hasn't slept the full period. The only way it wouldn't is unless the scheduler bases the sleep off of time (Which would have changed) and it processes this information upon restart. Of course, even if it is based off of time, generally the OS is probably notified of a hibernation and it could make special arrangements to honor the full sleep independent of the hibernation, ie, resume after the system restarted. I can't be sure of that without a test. You could write a thread to sleep and after the sleep write a debug message or something. Perform the test and verify the results. Though, generally speaking, the results could vary by implementation (hardware, OS, etc.) but most likely the implementations should match what you find. http://www.veritest.com/benchmarks/battmark/bb3power\_man/b3sleep.asp Hibernation Hibernation is one of several terms describing a state of reduced power consumption that a power-managed computer may support. According to the conventional definition of hibernation, a notebook copies all memory contents and hardware state information to non-volatile storage (typically the hard disk, which requires no power to retain information), and the notebook is completely powered down. Leaving hibernation and returning the system to full operation requires booting the computer as usual and then waiting while the system restores the memory contents and hardware state. The process is finished when the computer is at exactly the point it was when the hibernate process started. Hibernation trades time for power: maintaining the system state requires no power (beca

                                T Offline
                                T Offline
                                Toby Opferman
                                wrote on last edited by
                                #15

                                BTW, Sleep() calls SleepEx with FALSE.

                                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