提交 51aaac8d 编写于 作者: C chegar

6926623: Thread clone issues

Reviewed-by: hawtin
上级 73c6f8a0
...@@ -260,6 +260,10 @@ class Thread implements Runnable { ...@@ -260,6 +260,10 @@ class Thread implements Runnable {
/* Remembered Throwable from stop before start */ /* Remembered Throwable from stop before start */
private Throwable throwableFromStop; private Throwable throwableFromStop;
/* Whether or not the Thread has been completely constructed;
* init or clone method has successfully completed */
private volatile Thread me; // null
/** /**
* Returns a reference to the currently executing thread object. * Returns a reference to the currently executing thread object.
* *
...@@ -411,6 +415,43 @@ class Thread implements Runnable { ...@@ -411,6 +415,43 @@ class Thread implements Runnable {
/* Set thread ID */ /* Set thread ID */
tid = nextThreadID(); tid = nextThreadID();
this.me = this;
}
/**
* Returns a clone if the class of this object is {@link Cloneable Cloneable}.
*
* @return a clone if the class of this object is {@code Cloneable}
*
* @throws CloneNotSupportedException
* if this method is invoked on a class that does not
* support {@code Cloneable}
*/
@Override
protected Object clone() throws CloneNotSupportedException {
Thread t;
synchronized(this) {
t = (Thread) super.clone();
t.tid = nextThreadID();
t.parkBlocker = null;
t.blocker = null;
t.blockerLock = new Object();
t.threadLocals = null;
group.checkAccess();
group.addUnstarted();
t.setPriority(priority);
final Thread current = Thread.currentThread();
if (current.inheritableThreadLocals != null)
t.inheritableThreadLocals =
ThreadLocal.createInheritedMap(current.inheritableThreadLocals);
}
t.me = t;
return t;
} }
/** /**
...@@ -672,7 +713,7 @@ class Thread implements Runnable { ...@@ -672,7 +713,7 @@ class Thread implements Runnable {
* *
* A zero status value corresponds to state "NEW". * A zero status value corresponds to state "NEW".
*/ */
if (threadStatus != 0) if (threadStatus != 0 || this != me)
throw new IllegalThreadStateException(); throw new IllegalThreadStateException();
/* Notify the group that this thread is about to be started /* Notify the group that this thread is about to be started
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册