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. How to make my program the highest priority

How to make my program the highest priority

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
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.
  • J Offline
    J Offline
    jinzhecheng
    wrote on last edited by
    #1

    I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!

    B D 2 Replies Last reply
    0
    • J jinzhecheng

      I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      The SetPriorityClass function sets the priority class for the specified process. This value together with the priority value of each thread of the process determines each thread's base priority level.

      1 Reply Last reply
      0
      • J jinzhecheng

        I know in a program , you can create some threads,and assign different priority my question is: how to programmtically give your main thread the highest priority? Thanks alot!

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        jinzhecheng wrote:

        how to programmtically give your main thread the highest priority?

        Why would you want to do this? It would all but totally disable the OS.


        "Take only what you need and leave the land as you found it." - Native American Proverb

        J 1 Reply Last reply
        0
        • D David Crow

          jinzhecheng wrote:

          how to programmtically give your main thread the highest priority?

          Why would you want to do this? It would all but totally disable the OS.


          "Take only what you need and leave the land as you found it." - Native American Proverb

          J Offline
          J Offline
          jinzhecheng
          wrote on last edited by
          #4

          Here is the reason: Say I am testing the speed (I/O reading writting). I want the Max performance , the code would be like: tStart = getCurrentTime(); do{ reading(); writting(); } span = getCurrentTime()- tSpan; How can I ensure those steps are not interupted?

          D 1 Reply Last reply
          0
          • J jinzhecheng

            Here is the reason: Say I am testing the speed (I/O reading writting). I want the Max performance , the code would be like: tStart = getCurrentTime(); do{ reading(); writting(); } span = getCurrentTime()- tSpan; How can I ensure those steps are not interupted?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            The first thing to note is that GetCurrentTime() has been deprecated by GetTickCount(). Second, calling SetThreadPriority() with a priority greater than 11 may cause disk caches to not flush, hang the mouse, and so on.

            jinzhecheng wrote:

            How can I ensure those steps are not interupted?

            By using a critical section (e.g., InitializeCriticalSection()). I'm not sure you actually want to do this, however. If you are simply wanting to time a section of code, GetTickCount() is the way to do this. Since Windows is not a RTOS, you'll not ever get 100% accuracy. For example, let's say that, per your watch, the code took 5 seconds to execute. However, span had a value of 6000, or 6 seconds. That means that the code was preempted for a total of 1000 ms. This is not necessarily a bad thing. It's much like weighing yourself at home on a scale that is not 100% accurate. Whether it shows you to be too heavy or too light, it doesn't matter as long as it's consistent. By comparing one weigh with another from the same scale, you can judge for yourself whether you are gaining or losing weight. Make sense?


            "Take only what you need and leave the land as you found it." - Native American Proverb

            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