aboutsummaryrefslogtreecommitdiff
path: root/Tools/Hazel-Networking/Hazel/FewerThreads/HazelThreadPool.cs
blob: fb36b007af203275a6d9698469492f94fcc82327 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 { }
            }
        }
    }
}