diff options
author | Koundinya Veluri <kouvel@microsoft.com> | 2017-04-12 20:34:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 20:34:18 +0300 |
commit | c1e823f78d6289c1f3ed4d21d384c0a808b41c5e (patch) | |
tree | 98fb181e09e6aa596acb7c06df19523d2b262526 /src/System.Threading.ThreadPool | |
parent | 3f0b3f69c356dd7ad551f63c9ca69bf03d613fcc (diff) |
Add test for thread pool concurrent initialization (#18174)
Add test for thread pool concurrent initialization
Depends on dotnet/coreclr#10869
Fixes dotnet/coreclr#10521
Diffstat (limited to 'src/System.Threading.ThreadPool')
-rw-r--r-- | src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index 615e011bef..6dd31c3896 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -14,6 +14,39 @@ namespace System.Threading.ThreadPools.Tests private const int ExpectedTimeoutMilliseconds = ThreadTestHelpers.ExpectedTimeoutMilliseconds; private const int MaxPossibleThreadCount = 0x7fff; + static ThreadPoolTests() + { + // Run the following tests before any others + ConcurrentInitializeTest(); + } + + [Fact] + public static void ConcurrentInitializeTest() + { + int processorCount = Environment.ProcessorCount; + var countdownEvent = new CountdownEvent(processorCount); + Action threadMain = + () => + { + countdownEvent.Signal(); + countdownEvent.Wait(ThreadTestHelpers.UnexpectedTimeoutMilliseconds); + Assert.True(ThreadPool.SetMinThreads(processorCount, processorCount)); + }; + + var waitForThreadArray = new Action[processorCount]; + for (int i = 0; i < processorCount; ++i) + { + var t = ThreadTestHelpers.CreateGuardedThread(out waitForThreadArray[i], threadMain); + t.IsBackground = true; + t.Start(); + } + + foreach (Action waitForThread in waitForThreadArray) + { + waitForThread(); + } + } + [Fact] public static void GetMinMaxThreadsTest() { |