Trick to low CPU usage?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jakob Bieling

    #16
    OT: Re: Trick to low CPU usage?

    "Mike Smith" <mike_UNDERSCOR E_smith@acm.DOT .org> wrote in message
    news:vr50pue06k rp9c@news.super news.com...[color=blue]
    > Jakob Bieling wrote:[color=green]
    > >
    > > <Platform-Specific> On Windows you can use "Sleep" to have your[/color][/color]
    process[color=blue][color=green]
    > > sleep for n milliseconds. For other platforms I do not know.
    > > </Platform-Specific>[/color]
    >
    > <more-platform-specific> Sleep() does not guarantee an exact time. If
    > no other threads are ready to run, the Sleep()ing thread could
    > conceivably resume immediately[/color]

    It's right that it is not exact, but when you say 80ms, your thread is
    going to sleep for at least 80ms - guaranteed. This is why I suggested
    roughly 80-90ms for the timeout; the remaining 10-20ms are for executing
    code and for the inaccuracies.

    regards
    --
    jb

    (replace y with x if you want to reply by e-mail)


    Comment

    • Frank Schmitt

      #17
      Re: Trick to low CPU usage?

      Mike Smith <mike_UNDERSCOR E_smith@acm.DOT .org> writes:
      [color=blue]
      > Jakob Bieling wrote:[color=green]
      > > <Platform-Specific> On Windows you can use "Sleep" to have your
      > > process
      > > sleep for n milliseconds. For other platforms I do not know.
      > > </Platform-Specific>[/color]
      >
      > <more-platform-specific> Sleep() does not guarantee an exact time. If
      > no other threads are ready to run, the Sleep()ing thread could
      > conceivably resume immediately. A timer event might a the better way
      > to go. Does a corresponding thingy exist in Linux?</m-p-s>[/color]

      man nanosleep
      man 3 usleep

      HTH & kind regards
      frank

      --
      Frank Schmitt
      4SC AG phone: +49 89 700763-0
      e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com

      Comment

      • Eternally

        #18
        Re: Trick to low CPU usage?


        "Eternally" <m@r.com> wrote in message
        news:kokrb.2989 8$1N3.3032@twis ter.nyroc.rr.co m...[color=blue]
        > Hey folks,
        >
        > I'm writing a simple C++ application which runs continuously. I'm running
        > the program from the command line in Cygwin from XP, and it's
        > cross-compatible with Linux.
        >
        > While running the program, I notice that the CPU usage is 100%, with my
        > application stealing 97% of it.
        >
        > I'd like to bring that down to at most 10% of the CPU usage. What's the
        > trick to that?
        >
        > I noticed that on certain applications like those used to decode video,[/color]
        you[color=blue]
        > can specify how much CPU to use (high priority, low priority...), how is
        > that accomplished? How can I bring my applications CPU usage down to 10%?
        >
        > Note: I tried running sleep(1), and that brought it down below 10%,[/color]
        however[color=blue]
        > telling it to sleep for a full second is too much. A tenth of a second
        > would be fine, but sleep only takes ints. I then tried using clock() and
        > making it pause until a certain amount of time had passed like .005 of a
        > second, but the cpu sticks at 100% with that method (since it's running in[/color]
        a[color=blue]
        > while loop testing the amount of time passed....i.e. it's not really
        > sleeping).
        >
        > Thanks in advance for the help!
        >
        >[/color]

        Thanks everyone! usleep did the trick!


        Comment

        Working...