Расчет математического выражения с помощью потоков — C#(Си шарп)

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
 
namespace ConsoleApplication1
{
    class Program
    {
        static double n = 1;
        static object locker = new object();
        static double eps = 0.000001, sum = 0, prev = 0;
        static void Function_of_thread()
        {
            lock (locker)
            {
                prev = sum;
                sum += 1 / (Math.Pow(n, 4));
                ++n;
                Console.WriteLine("Япоток №" + n + " SUM=" + sum);
            }
        }
 
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Thread thr = new Thread(Function_of_thread);
                thr.Start();
            }
            Console.Read();
 
        }
    }
}

Leave a Comment