3 using System
.Collections
.Concurrent
;
4 using System
.Collections
.Generic
;
5 using System
.Threading
;
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
));
30 Console
.WriteLine ("Started thread {0} ({1} running concurrently)", worker
.ManagedThreadId
, threads
.Count
);
33 threads
.CompleteAdding ();
36 Thread consumer
= new Thread (new ThreadStart(() => {
37 while (!threads
.IsCompleted
) {
38 Thread worker
= threads
.Take ();
40 Console
.WriteLine ("Joined thread {0}", worker
.ManagedThreadId
);