[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] Implementing Thread.sleep() via Thread.wait()
From: |
Archie Cobbs |
Subject: |
Re: [cp-patches] Implementing Thread.sleep() via Thread.wait() |
Date: |
Fri, 31 Dec 2004 14:50:33 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129 |
Mark Wielaard wrote:
Good point.. I've reimplemented this in VMThread.sleep() instead.
Let me know what you think.
Could you please supply a ChangeLog entry. that makes reviewing much
easier.
* NEWS, java/lang/Thread.java, vm/reference/java/lang/VMThread.java:
treat Thread.sleep(0) like Thread.yield() for JDK compatibility,
and add a non-native implementation of VMThread.sleep().
Confidentiality Notice
Please don't add such things to your emails. This is a public
mailinglist that is mirrored in a couple of places and forwarded to
public newsgroups.
You really think I have control over that? :-) When I send email from
my workplace (which is behind the firewall of a large hospital) it gets
added automatically. Please accept my apologies.
--- NEWS 30 Dec 2004 13:18:17 -0000 1.61
+++ NEWS 30 Dec 2004 23:11:53 -0000
@@ -14,9 +14,7 @@
* String and StringBuffer now call VMSystem.arraycopy() directly and don't
go through java.lang.System. Be careful to not initialize java.lang.System
early in the bootstrap sequence in your VM runtime interface classes.
-* VMThread.sleep() will never be called with zero arguments (don't sleep).
- VMThread does not have to do any extra argument checking. Some (wrong)
- documentation about the behavior of this method has been updated.
+* VMThread.sleep() now has a default non-native implementation.
Could you please keep the discription I added. And please mention that
the default implementation provided is a generic implementation that
ignores the nano-seconds argument. Runtime hackers are encouraged to
provide a more efficient version.
As I mentioned, the removal was inadvertent. How's this instead:
Index: NEWS
===================================================================
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.61
diff -u -r1.61 NEWS
--- NEWS 30 Dec 2004 13:18:17 -0000 1.61
+++ NEWS 31 Dec 2004 20:47:27 -0000
@@ -17,6 +17,9 @@
* VMThread.sleep() will never be called with zero arguments (don't sleep).
VMThread does not have to do any extra argument checking. Some (wrong)
documentation about the behavior of this method has been updated.
+ Also, VMThread.sleep() now has a default non-native implementation, but
+ it is a generic implementation that ignores the nano-seconds argument.
+ Runtime hackers are encouraged to provide a more efficient version.
+ * <p>
+ * A zero length sleep is equivalent to <code>Thread.yield()</code>.
I think this is not a good idea. This is not supported by any
documentation. And I agree with you that it is probably a bug in the
implementation you tested and filed a bug report for the fact that
sleep(0) seems to ignore the interrupted state of the Thread. And if we
want to add this bug to our implementation (and I think we shouldn't)
why Thread.yield(), why not just return?
Because that's what the JDK does. E.g., watch the output of this program:
public class zz extends Thread {
private final int num;
public zz(int num) {
this.num = num;
}
public void run() {
try {
System.out.println("thread " + num);
Thread.sleep(0);
System.out.println("thread " + num);
Thread.sleep(0);
System.out.println("thread " + num);
Thread.sleep(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Exception {
new zz(1).start();
new zz(2).start();
new zz(3).start();
}
}
-Archie
__________________________________________________________________________
Archie Cobbs * CTO, Awarix * http://www.awarix.com
- [cp-patches] Implementing Thread.sleep() via Thread.wait(), Archie Cobbs, 2004/12/30
- RE: [cp-patches] Implementing Thread.sleep() via Thread.wait(), Jeroen Frijters, 2004/12/31
- RE: [cp-patches] Implementing Thread.sleep() via Thread.wait(), Jeroen Frijters, 2004/12/31
- RE: [cp-patches] Implementing Thread.sleep() via Thread.wait(), Jeroen Frijters, 2004/12/31
- RE: [cp-patches] Implementing Thread.sleep() via Thread.wait(), Jeroen Frijters, 2004/12/31