Changes for galois
[IRC.git] / Robust / src / ClassLibrary / MGC / Thread.java
1 public class Thread implements Runnable {
2   static long id = 0;
3   private boolean finished;
4   Runnable target;
5   private boolean daemon;
6   private long threadId;
7   String name;
8   final ThreadLocalMap locals;
9   
10   public Thread(){
11     finished = false;
12     target = null;
13     daemon = false;
14     threadId = Thread.id++;
15     locals = new ThreadLocalMap();
16   }
17   
18   public long getId()
19   {
20     return threadId;
21   }
22   
23   public Thread(Runnable r) {
24     finished = false;
25     target = r;
26     daemon = false;
27     threadId = Thread.id++;
28     locals = new ThreadLocalMap();
29   }
30   
31   public Thread(Runnable r, String n)
32   {
33     finished = false;
34     target = r;
35     name = n;
36     daemon = false;
37     threadId = Thread.id++;
38     locals = new ThreadLocalMap();
39   }
40
41   public void start() {
42     nativeCreate();
43   }
44
45   private static void staticStart(Thread t) {
46     t.run();
47     t.finished = true;
48   }
49
50   public static native void yield();
51
52   public void join() {
53     nativeJoin();
54   }
55
56   private native void nativeJoin();
57
58   public native static void sleep(long millis);
59
60   public void run() {
61     if(target != null) {
62       target.run();
63     }
64     this.finished = true;
65   }
66
67   private native void nativeCreate();
68   
69   public final boolean isAlive() {
70     return !this.finished;
71   }
72   
73   public static ThreadLocalMap getThreadLocals() {
74       return currentThread().locals;
75   }
76   
77   public final synchronized void setDaemon(boolean daemon) {
78     /*if (vmThread != null)
79       throw new IllegalThreadStateException();
80     checkAccess();*/
81     this.daemon = daemon;
82   }
83   
84   public native static Thread currentThread();
85   
86   /*public static Map getAllStackTraces() {
87     System.out.println("Unimplemented Thread.getAllStackTraces()");
88     return new HashMap();
89   }*/
90   
91 }