Implemented Thread.join()

This commit is contained in:
Steve Hannah 2015-06-02 10:38:33 -07:00
parent 1fd4b8ff7a
commit 83497b1b9e

View File

@ -36,6 +36,8 @@ public class TThread extends TObject implements TRunnable {
private int priority = 0; private int priority = 0;
private long timeSliceStart; private long timeSliceStart;
private int yieldCount; private int yieldCount;
private final Object finishedLock = new Object();
private TString name; private TString name;
TRunnable target; TRunnable target;
@ -90,6 +92,9 @@ public class TThread extends TObject implements TRunnable {
if (target != null) { if (target != null) {
target.run(); target.run();
} }
synchronized(finishedLock) {
finishedLock.notifyAll();
}
} }
public static TThread currentThread() { public static TThread currentThread() {
@ -100,6 +105,23 @@ public class TThread extends TObject implements TRunnable {
return name; return name;
} }
public final void join(long millis, int nanos) throws InterruptedException {
if (currentThread() == this) {
return;
}
synchronized(finishedLock) {
finishedLock.wait(millis, nanos);
}
}
public final void join(long millis) throws InterruptedException {
join(millis, 0);
}
public final void join() throws InterruptedException {
join(0);
}
public static void yield() { public static void yield() {
TThread currentThread = currentThread(); TThread currentThread = currentThread();
if (++currentThread.yieldCount < 30) { if (++currentThread.yieldCount < 30) {