3 using System
.Threading
;
4 using System
.Collections
;
5 using System
.Collections
.Generic
;
10 static object count_lock
= new object();
12 const long N
= 500000;
13 const int num_threads
= 8;
15 static void UseMemory () {
17 for (int i
= 0; i
< N
; ++i
) {
19 var l1
= new ArrayList ();
21 var l2
= new ArrayList ();
23 var l3
= new ArrayList ();
25 var l4
= new ArrayList ();
33 Monitor
.PulseAll(count_lock
);
37 static void Timer_Elapsed(object sender
, EventArgs e
)
39 HashSet
<string> h
= new HashSet
<string>();
40 for (int j
= 0; j
< 10000; j
++)
46 static void Main (string[] args
) {
47 var testTimeout
= new TestTimeout ();
50 const int TOTAL_ITERATIONS
= 2;
51 for (int j
= 0; j
< TOTAL_ITERATIONS
; j
++)
55 List
<Thread
> threads
= new List
<Thread
>();
56 List
<System
.Timers
.Timer
> timers
= new List
<System
.Timers
.Timer
>();
58 for (int i
= 0; i
< num_threads
; i
++)
60 Thread t3
= new Thread (delegate () {
66 System
.Timers
.Timer timer
= new System
.Timers
.Timer();
67 timer
.Elapsed
+= Timer_Elapsed
;
68 timer
.AutoReset
= false;
69 timer
.Interval
= 1000;
74 for (int i
= 0; i
< 4000; i
++)
76 System
.Timers
.Timer timer
= new System
.Timers
.Timer();
77 timer
.Elapsed
+= Timer_Elapsed
;
78 timer
.AutoReset
= false;
86 while (count
< num_threads
)
89 Monitor
.Wait(count_lock
);
93 foreach (var t
in threads
)
99 if (!testTimeout
.HaveTimeLeft ()) {
100 var finishTime
= DateTime
.UtcNow
;
101 var ranFor
= finishTime
- testTimeout
.StartTime
;
102 Console
.WriteLine ("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor
, j
+1, TOTAL_ITERATIONS
);
106 Console
.WriteLine ("done");