aboutsummaryrefslogtreecommitdiff
path: root/Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs')
-rw-r--r--Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs b/Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs
new file mode 100644
index 0000000..fb36b00
--- /dev/null
+++ b/Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Hazel
+{
+ internal class HazelThreadPool
+ {
+ private Thread[] threads;
+
+ public HazelThreadPool(int numThreads, ThreadStart action)
+ {
+ this.threads = new Thread[numThreads];
+ for (int i = 0; i < this.threads.Length; ++i)
+ {
+ this.threads[i] = new Thread(action);
+ }
+ }
+
+ public void Start()
+ {
+ for (int i = 0; i < this.threads.Length; ++i)
+ {
+ this.threads[i].Start();
+ }
+ }
+
+ public void Join()
+ {
+ for (int i = 0; i < this.threads.Length; ++i)
+ {
+ var thread = this.threads[i];
+ try
+ {
+ thread.Join();
+ }
+ catch { }
+ }
+ }
+ }
+} \ No newline at end of file