private void ThreadFnc object ThreadNumber _pool WaitOne for int int T

 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
private void ThreadFnc(object ThreadNumber) {
_pool.WaitOne();
for (int i = (int)ThreadNumber; i < this.Size; i += this.ThreadsNumber) {
for (int j = 0; j < this.Size; j++) {
this.FinalMatrix[i, j] = 0;
for (int k = 0; k < this.Size; k++) {
this.FinalMatrix[i, j] += this.FirstMatrix[i, k] * this.SecondMatrix[k, j];
}
}
}
}
public void DoMultiply() {
threads = new List<Thread>();
this.StatOfThreads = new int[this.ThreadsNumber];
for (int j = 1; j <= this.ThreadsNumber; j++) {
this._pool = new Semaphore(0, j);
Stopwatch sw = new Stopwatch();
sw.Reset();
sw.Start();
for (int i = 0; i < j; i++) {
threads.Add(new Thread(new ParameterizedThreadStart(this.ThreadFnc)));
threads[threads.Count-1].Start(i);
}
Thread.Sleep(500);
_pool.Release(j);
sw.Stop();
this.StatOfThreads[j-1] = Convert.ToInt32(sw.ElapsedMilliseconds);
}
}