[System] Tweak socket test
[mono-project.git] / mono / tests / process-unref-race.cs
blob589257f40ca8ddfcdc41702813e0bd62ea232ff0
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 Parallel.ForEach (UntilTimeout (15 * 1000), options, _ => {
28 using (Process p = Process.Start ("cat", "/dev/null")) {
29 p.WaitForExit ();
32 lock (count_lock) {
33 count += 1;
35 if (count % (10) == 0)
36 Console.Write (".");
37 if (count % (10 * 50) == 0)
38 Console.WriteLine ();
40 });
41 });
43 t1.Start ();
45 while (!t1.Join (0)) {
46 try {
47 using (Process p = Process.GetProcessById (1));
48 } catch (ArgumentException) {