4
using System.Threading;
5
using System.Collections.Generic;
7
internal class Thread : Runnable
9
private static ThreadGroup defaultGroup = new ThreadGroup ();
10
private bool interrupted;
11
private Runnable runnable;
12
private ThreadGroup tgroup;
13
private System.Threading.Thread thread;
16
private static Sharpen.Thread wrapperThread;
18
public Thread () : this(null, null, null)
22
public Thread (string name) : this (null, null, name)
26
public Thread (ThreadGroup grp, string name) : this (null, grp, name)
30
public Thread (Runnable runnable): this (runnable, null, null)
34
Thread (Runnable runnable, ThreadGroup grp, string name)
36
thread = new System.Threading.Thread (new ThreadStart (InternalRun));
38
this.runnable = runnable ?? this;
39
tgroup = grp ?? defaultGroup;
45
private Thread (System.Threading.Thread t)
48
tgroup = defaultGroup;
52
public static Sharpen.Thread CurrentThread ()
54
if (wrapperThread == null) {
55
wrapperThread = new Sharpen.Thread (System.Threading.Thread.CurrentThread);
60
public string GetName ()
65
public ThreadGroup GetThreadGroup ()
70
private void InternalRun ()
75
} catch (Exception exception) {
76
Console.WriteLine (exception);
82
public static void Yield ()
86
public void Interrupt ()
94
public static bool Interrupted ()
96
if (Sharpen.Thread.wrapperThread == null) {
99
Sharpen.Thread wrapperThread = Sharpen.Thread.wrapperThread;
100
lock (wrapperThread) {
101
bool interrupted = Sharpen.Thread.wrapperThread.interrupted;
102
Sharpen.Thread.wrapperThread.interrupted = false;
107
public bool IsAlive ()
109
return thread.IsAlive;
117
public void Join (long timeout)
119
thread.Join ((int)timeout);
122
public virtual void Run ()
126
public void SetDaemon (bool daemon)
128
thread.IsBackground = daemon;
131
public void SetName (string name)
136
public static void Sleep (long milis)
138
System.Threading.Thread.Sleep ((int)milis);
153
internal class ThreadGroup
155
private List<Thread> threads = new List<Thread> ();
161
public ThreadGroup (string name)
165
internal void Add (Thread t)
172
internal void Remove (Thread t)
179
public int Enumerate (Thread[] array)
182
int count = Math.Min (array.Length, threads.Count);
183
threads.CopyTo (0, array, 0, count);