[2020-02] Avoid following invalid pointers in mono_w32process_get_modules on Darwin...
[mono-project.git] / mono / tests / process-unref-race.cs
blob46ef4b2a9c581f97362e13d2ab4738c91934ef0f
2 using System;
3 using System.Collections.Generic;
4 using System.Diagnostics;
5 using System.Threading;
6 using System.Threading.Tasks;
8 class Driver
10 static IEnumerable<int> UntilTimeout (uint ms)
12 DateTime start = DateTime.UtcNow;
13 for (int i = 0; (DateTime.UtcNow - start).TotalMilliseconds < ms ; i++)
14 yield return i;
17 public static void Main ()
19 object count_lock = new object ();
20 int count = 0;
22 ParallelOptions options = new ParallelOptions {
23 MaxDegreeOfParallelism = Environment.ProcessorCount * 4,
26 Thread t1 = new Thread (() => {
27 ProcessStartInfo psi = new ProcessStartInfo () {
28 FileName = "echo",
29 Arguments = "hello",
30 RedirectStandardOutput = true,
31 UseShellExecute = false
34 Parallel.ForEach (UntilTimeout (15 * 1000), options, _ => {
35 using (Process p = Process.Start (psi)) {
36 p.BeginOutputReadLine ();
37 p.WaitForExit ();
40 lock (count_lock) {
41 count += 1;
43 if (count % (10) == 0)
44 Console.Write (".");
45 if (count % (10 * 50) == 0)
46 Console.WriteLine ();
48 });
49 });
51 t1.Start ();
53 while (!t1.Join (0)) {
54 try {
55 using (Process p = Process.GetProcessById (1));
56 } catch (ArgumentException) {