blob: c4b8cf5be502f608b33daca46c37420153fdef2c (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static int returnVal = 100;
static byte[][] s = new byte[1000][];
static void Work()
{
for (uint i = 0; i < 1000000; i++)
{
var a = s[i++ % s.Length];
ref byte p = ref a[0];
ref byte q = ref a[1];
if (Unsafe.ByteOffset(ref p, ref q) != new IntPtr(1))
{
Console.WriteLine("ERROR: i = " + i);
returnVal = -1;
}
p = 1; q = 2;
}
}
static int Main(string[] args)
{
for(int i = 0; i < s.Length; i++) s[i] = new byte[2];
List<Task> tasks = new List<Task>();
for(int i = 0; i < 5; i++)
{
tasks.Add(Task.Run(Work));
}
Random r = new Random();
for (uint i = 0; i < 10000; i++)
{
s[r.Next(s.Length)] = new byte[3 + r.Next(100)];
}
Task t = Task.WhenAll(tasks);
t.Wait();
return returnVal;
}
}
|