Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. int n = 10;
  2.             short []tab = new short[n];
  3.             Random rand = new Random();
  4.  
  5.             Parallel.For(0, n, i =>
  6.             {
  7.                 tab[i] = (short)rand.Next(0, 5);
  8.             });
  9.  
  10.             long total = 0;
  11.             Parallel.For<short>(0, n, () => 0, (j, loop, subtotal) =>
  12.             {
  13.                 subtotal += tab[j];
  14.                 return subtotal;
  15.             },
  16.                 (x) => Interlocked.Add(ref total, x)
  17.             );
  18.             Console.WriteLine("Suma {0}", total);
  19.             Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement