Joseph Shraibman wrote:
Hui Huang wrote:

Joseph Shraibman wrote:

Alexander V. Konstantinou wrote:

Actually, thread priorities work fine in Linux.



No, they don't, not with the latest sun jdk on redhat 8.0.

Thread priority is just a hint (same applies to Thread.yield()).

While the jvm authors can't do anything about the kernel ignoring the priority, they *can* do something about Thread.yield(): make it the equivalent to sleep(1)
No. sleep(0) would come close, not sleep(1).

Thread.yield() is used under two different scenarios:
  + waiting for certain condition to become true (or false), most
    likely this is used in a yield loop, and current thread has
    nothing to do but burning CPU cycles in a while loop.
  + be nice and let kernel/pthread know that this would be a good
    point to schedule another thread to run, current thread still has
    some work to do. Such yields are necessary for non-preemptive
    schedulers (e.g. green thread).

In the first case, it's probably OK to sleep(1), but it makes
no sense for the second case. And you can always sleep on a
monitor instead in the first case, it's better than yield.
sleep(0) is acceptable for both cases, but again with sleep(0),
it's up to the scheduler to decide if or not to actually switch
context.


kernel space. JDK passes the priority information to the kernel,

How?
pthread_setschedparam. Note that sched_priority is ignored under
SCHED_OTHER policy.


but they are ignored.

It may sound like a surprise, but most of the time kernel scheduler
can do a better job than human in prioritizing jobs.

Um, no. The few cases I would set a priority I would have a good reason.

BTW does the jvm give threads with higher prio prefrence when delivering notify()'s?

No, IIRC.

-hui


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to