[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / sgen-new-threads-dont-join-stw-2.cs
blob41998c7e2866098feb88cadec91684e6a5bd47cd
2 using System;
3 using System.Collections.Concurrent;
4 using System.Collections.Generic;
5 using System.Threading;
7 class Driver
9 public static void Main ()
11 BlockingCollection<Thread> threads = new BlockingCollection<Thread> (128);
13 Thread producer = new Thread (new ThreadStart (() => {
14 DateTime start = DateTime.Now;
16 for (TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 120 : 5)); timeout.HaveTimeLeft;) {
17 Thread worker = new Thread (new ThreadStart (() => {
18 HashSet<string> hashset = new HashSet<string> ();
19 for (int i = 0; i < 50000; ++i) {
20 hashset.Add(string.Concat (i, i));
21 if (i % 10 == 0)
22 Thread.Yield ();
24 }));
26 worker.Start ();
28 threads.Add (worker);
30 Console.WriteLine ("Started thread {0} ({1} running concurrently)", worker.ManagedThreadId, threads.Count);
33 threads.CompleteAdding ();
34 }));
36 Thread consumer = new Thread (new ThreadStart(() => {
37 while (!threads.IsCompleted) {
38 Thread worker = threads.Take ();
39 worker.Join ();
40 Console.WriteLine ("Joined thread {0}", worker.ManagedThreadId);
42 }));
44 producer.Start ();
45 consumer.Start ();
47 producer.Join ();
48 consumer.Join ();