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. Alternative to Sleep(0)?

Alternative to Sleep(0)?

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

    While using Sleep(0), I've noticed lag when the process context is switched to the next application. It seems almost as if Sleep(0) is causing the processor to thrash between apps. Maybe I'm just :~. I was wondering if any of you have noticed something similar? Also, other than thread priority is there a way to relinquish thread control? Just as an afterthought. For a while I ran the United Devices Cure for Cancer app. I noticed that it kept the CPU pegged but I was never able to tell when the process context switched. I wonder what they used. nay

    T 1 Reply Last reply
    0
    • N nay

      While using Sleep(0), I've noticed lag when the process context is switched to the next application. It seems almost as if Sleep(0) is causing the processor to thrash between apps. Maybe I'm just :~. I was wondering if any of you have noticed something similar? Also, other than thread priority is there a way to relinquish thread control? Just as an afterthought. For a while I ran the United Devices Cure for Cancer app. I noticed that it kept the CPU pegged but I was never able to tell when the process context switched. I wonder what they used. nay

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      Why are you using Sleep(0)? Why do you feel the need to stall the thread? Tim Smith I'm going to patent thought. I have yet to see any prior art.

      N 1 Reply Last reply
      0
      • T Tim Smith

        Why are you using Sleep(0)? Why do you feel the need to stall the thread? Tim Smith I'm going to patent thought. I have yet to see any prior art.

        N Offline
        N Offline
        nay
        wrote on last edited by
        #3

        Other applications are running concurrently. I do not want one to "hog" resources. From the MSDN Sleep(0) is what I want, but I'm not satisfied with the performance of it. I was just curious if there was another solution. nay

        B T 2 Replies Last reply
        0
        • N nay

          Other applications are running concurrently. I do not want one to "hog" resources. From the MSDN Sleep(0) is what I want, but I'm not satisfied with the performance of it. I was just curious if there was another solution. nay

          B Offline
          B Offline
          Brian Shifrin
          wrote on last edited by
          #4

          If you have one thread that just wants to peg CPU, use Sleep(50); ... Sleep(200);

          1 Reply Last reply
          0
          • N nay

            Other applications are running concurrently. I do not want one to "hog" resources. From the MSDN Sleep(0) is what I want, but I'm not satisfied with the performance of it. I was just curious if there was another solution. nay

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #5

            Windows is a preemptive multi-tasker. It will periodically suspend your process to allow other things to run. If that isn't good enough for the thread in question, then force the priority of the thread to a lower level. Thus, if the use tries to work with practically any other window, they will be responsive. There just isn't any justification for using Sleep on a real multi-tasking operating system. It causes excessive kernel transitions to do something that the OS is already designed to do for you. Tim Smith I'm going to patent thought. I have yet to see any prior art.

            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