diff options
author | chai <215380520@qq.com> | 2023-10-12 22:09:49 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-12 22:09:49 +0800 |
commit | 8d2a2cd5de40e2b94ef5007c32832ed9a063dc40 (patch) | |
tree | a63dfbe815855925c9fb8f2804bd6ccfeffbd2eb /Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs | |
parent | dd0c5d50e377d9be1e728463670908a6c9d2c14f (diff) |
+hazel-networking
Diffstat (limited to 'Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs')
-rw-r--r-- | Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs | 44 |
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 |