Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static byte[] tab;
- static int result;
- static Thread t1, t2;
- static void Main(string[] args)
- {
- result = 0;
- Random rand = new Random();
- tab = new byte[1000];
- for (int i = 0; i < 1000; i++)
- tab[i] = (byte)rand.Next(0, 10);
- t1 = new Thread(add);
- t2 = new Thread(add);
- t1.Start(0);
- t2.Start(500);
- t2.Join();
- Console.WriteLine(result);
- Console.ReadKey();
- }
- static void add(object o)
- {
- int tmp = 0;
- int start = (int)o;
- int result=0;
- for(int i=start;i<start+500;i++)
- tmp +=tab[i];
- if (start == 500)
- t1.Join();
- result += tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement