forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcse-array-index-byref.cs
More file actions
35 lines (31 loc) · 921 Bytes
/
cse-array-index-byref.cs
File metadata and controls
35 lines (31 loc) · 921 Bytes
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xunit;
public class CseArrayIndexByref
{
[Fact]
public static void TestEntryPoint()
{
int[] arr = new int[1];
AsyncTestEntryPoint(arr, 0).Wait();
Assert.Equal(199_990_000, arr[0]);
}
[System.Runtime.CompilerServices.RuntimeAsyncMethodGeneration(false)]
private static async Task AsyncTestEntryPoint(int[] arr, int index)
{
await HoistedByref(arr, index);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task<int> HoistedByref(int[] arr, int index)
{
for (int i = 0; i < 20000; i++)
{
arr[index] += i;
await Task.Yield();
}
return 0;
}
}