Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. static byte[] tab;
  2.         static int result;
  3.         static Thread t1, t2;
  4.  
  5.         static void Main(string[] args)
  6.         {
  7.             result = 0;
  8.             Random rand = new Random();
  9.             tab = new byte[1000];
  10.             for (int i = 0; i < 1000; i++)
  11.                 tab[i] = (byte)rand.Next(0, 10);
  12.             t1 = new Thread(add);
  13.             t2 = new Thread(add);
  14.             t1.Start(0);
  15.             t2.Start(500);
  16.             t2.Join();
  17.             Console.WriteLine(result);
  18.             Console.ReadKey();
  19.         }
  20.  
  21.         static void add(object o)
  22.         {
  23.             int tmp = 0;
  24.             int start = (int)o;            
  25.             int result=0;
  26.             for(int i=start;i<start+500;i++)
  27.                 tmp +=tab[i];
  28.             if (start == 500)
  29.                 t1.Join();
  30.             result += tmp;
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement