Merge pull request #122 from shannah/add_thread_join

Implemented Thread.join()
This commit is contained in:
Alexey Andreev 2015-06-05 17:04:13 +03:00
commit 2e2ab98e38

View File

@ -36,6 +36,8 @@ public class TThread extends TObject implements TRunnable {
private int priority = 0;
private long timeSliceStart;
private int yieldCount;
private final Object finishedLock = new Object();
private TString name;
TRunnable target;
@ -90,6 +92,9 @@ public class TThread extends TObject implements TRunnable {
if (target != null) {
target.run();
}
synchronized(finishedLock) {
finishedLock.notifyAll();
}
}
public static TThread currentThread() {
@ -100,6 +105,23 @@ public class TThread extends TObject implements TRunnable {
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() {
TThread currentThread = currentThread();
if (++currentThread.yieldCount < 30) {