Untitled
unknown
plain_text
3 years ago
885 B
11
Indexable
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
long sum1 = 0, sum2 = 0;
AutoResetEvent t1Event = new AutoResetEvent(false);
AutoResetEvent t2Event = new AutoResetEvent(false);
Thread t1 = new Thread(() =>
{
for (int i = 1; i <= 1000; i++)
{
sum1 += i * i;
}
t1Event.Set();
});
Thread t2 = new Thread(() =>
{
for (int i = 1001; i <= 2000; i++)
{
sum2 += i * i;
}
t2Event.Set();
});
t1.Start();
t2.Start();
t1Event.WaitOne();
t2Event.WaitOne();
Console.WriteLine("Sum 1: " + sum1);
Console.WriteLine("Sum 2: " + sum2);
Console.ReadKey();
}
}
Editor is loading...