65 lines
1.9 KiB
Plaintext
65 lines
1.9 KiB
Plaintext
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Microsoft Research Singularity
|
||
|
//
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
//
|
||
|
// File: HeapTest.cs
|
||
|
//
|
||
|
// Note: Allocate strings and encourage GCs
|
||
|
//
|
||
|
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Threading;
|
||
|
|
||
|
using Microsoft.Singularity.UnitTest;
|
||
|
|
||
|
namespace Microsoft.Singularity.Applications
|
||
|
{
|
||
|
public class ForkTest
|
||
|
{
|
||
|
static readonly string []! ProcessArgs = new string[] { "testpe.x86" };
|
||
|
static readonly TimeSpan ProcessTimeout = TimeSpan.FromSeconds(10);
|
||
|
const int IterationsPerThread = 64;
|
||
|
|
||
|
static object! monitor = new object();
|
||
|
static AutoResetEvent! exitEvent = new AutoResetEvent(false);
|
||
|
static int threadCount;
|
||
|
|
||
|
private static void ThreadMain()
|
||
|
{
|
||
|
lock (ForkTest.monitor) {
|
||
|
ForkTest.threadCount++;
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < IterationsPerThread; i++) {
|
||
|
Process process = new Process(ForkTest.ProcessArgs);
|
||
|
process.Start();
|
||
|
Assert.True(process.Join(ProcessTimeout),
|
||
|
"Failed to join process.");
|
||
|
}
|
||
|
|
||
|
lock (ForkTest.monitor) {
|
||
|
ForkTest.threadCount--;
|
||
|
if (ForkTest.threadCount == 0) {
|
||
|
ForkTest.exitEvent.Set();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void Run()
|
||
|
{
|
||
|
ForkTest.monitor = new object();
|
||
|
ForkTest.exitEvent = new AutoResetEvent(false);
|
||
|
ForkTest.threadCount = 0;
|
||
|
|
||
|
for (int i = 0; i < Settings.MaxThreads; i++) {
|
||
|
Thread t = new Thread(new ThreadStart(ThreadMain));
|
||
|
t.Start();
|
||
|
}
|
||
|
ForkTest.exitEvent.WaitOne();
|
||
|
}
|
||
|
}
|
||
|
}
|