Hui Huang wrote:
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).
Except I looked at the code and sleep(0) doesn't do anything. At least when I looked.
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.
Uh, sure, forcing yourself to sleep means another thread will be scheduled.
And you can always sleep on a
monitor instead in the first case,
Unless you are a lazy coder ;)
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]