Re: How to run tasks with priority?



"George George via JavaKB.com" <forum@xxxxxxxxxx> schreef in bericht
news:8512f8b20f86414fb983832c307581e9@xxxxxxxxxxxxx
> Thanks Boudewijn,
>
>
> Boudewijn Dijkstra wrote:
>>> Thanks Boudewijn,
>>>
>>[quoted text clipped - 12 lines]
>>> I am wondering whether your testing method will work. Since if there is
>>> only one thread in the system, yield will have no effect.
>>
>>In this case "no effect" means that it will continue running, i.e. not
>>sleeping.
>>
>>> But in your
>>> description, there are only one thread. Our testing purpose is to verify
>>[quoted text clipped - 3 lines]
>>> Maybe it is my mis-understanding of your description. It is highly
>>> appreciated if you could write down your ideas into sample source codes.
>>
>>Agreed, but only because I became curious myself. ;)
>>Running the following test application should be accompanied by a CPU-usage
>>monitor program. First it will do a yield-test for 10 seconds, then it will
>>do a sleep-test for 10 seconds. Observe the difference in CPU usage. The
>>getFinalScore method doesn't really serve any purpose, besides maybe the
>>calculation of (TEST_TIME / WAIT_TIME).
>>
>
> Your sample program is great! You mentioned that I should use CPU monitor
> program. So I have tried and used performance monitor of task manager of
> Windows XP (invoked from "My Computer") to monitor CPU usage. Am I correct?

That is fine for this example. ;)

> I have found that when yield is running, the CPU usage is very high, and
> when sleep is running, te CPU usage is very slow. Do you know why when
> running yield, CPU usage is high? What is CPU busy doing at that time (in
> my mind, I think CPU has nothing to do when running yield, just as when
> running sleep)?

The API documentation description of yield() is a bit cumbersome. But it is
enough for those who are educated in the most important concepts of task
scheduling. Sensing that you are not, I will explain what happens when
yield() is called.

1. The current thread is paused, but remains ready to run.
2. The task scheduler checks the current priority queue for threads (other
than the current one) that are ready to run.
3a. If there are, then perform a task-switch to the first one.
3b. If there aren't, then un-pause the current thread.

Note that, although the current thread is suspended, the CPU always has
something to run during steps 1,2,3.

> Another small issue is that, why you use join method in your getFinalScore
> method? I have not seen its special functons yet.

When 'running' is set to false, the thread does not immediately exit. By
calling join(), the thread that executes getFinalScore() waits for it to exit
so that it can fetch the *final* score.


.



Relevant Pages

  • Re: [PATCH] mm: yield during swap prefetching
    ... chance that prefetching will avoid it means even the CPU usage is ... Using sched_yieldseems like a hack though. ... Funny how at last I find a place where yield ...
    (Linux-Kernel)
  • Re: Program that can monitor CPU usage
    ... We want to trigger something based on high and low system LPAR ... What CPU Usage do you want an alert on? ... Currently RMF is the monitor in the operating system. ...
    (bit.listserv.ibm-main)
  • Re: WMP10 and CPU usage
    ... If you run a registry monitor on the system monitoring only wmplayer.exe - ... what's WMP freaking out about? ... > Has anyone out there had any luck with getting CPU usage under control if ...
    (microsoft.public.windowsmedia.player)
  • Re: How to run tasks with priority?
    ... >> I am wondering whether your testing method will work. ... You mentioned that I should use CPU monitor ... Windows XP to monitor CPU usage. ... running yield, CPU usage is high? ...
    (comp.lang.java.help)
  • Re: How to monitor the cpu usage?
    ... >> On our HP machines we can do so via top, but it seems its not part of ... monitor fast was the cpu usage. ... BTW: I solved the problem today: it was an faulty switch - using ...
    (comp.unix.sco.misc)