blob: b6d0a9b693b87a557298e60566528b2934ef5bf4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
using System;
using System.Timers;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
class T {
static int count = 0;
static object count_lock = new object();
const long N = 500000;
const int num_threads = 8;
static void UseMemory () {
for (int i = 0; i < N; ++i) {
var l1 = new ArrayList ();
l1.Add(""+i);
var l2 = new ArrayList ();
l2.Add(""+(i+1));
var l3 = new ArrayList ();
l3.Add(""+(i+2));
var l4 = new ArrayList ();
l4.Add(""+(i+3));
}
lock (count_lock)
{
count++;
Monitor.PulseAll(count_lock);
}
}
static void Timer_Elapsed(object sender, EventArgs e)
{
HashSet<string> h = new HashSet<string>();
for (int j = 0; j < 10000; j++)
{
h.Add(""+j+""+j);
}
}
static void Main (string[] args) {
for (int j = 0; j < 2; j++)
{
count = 0;
List<Thread> threads = new List<Thread>();
List<System.Timers.Timer> timers = new List<System.Timers.Timer>();
for (int i = 0; i < num_threads; i++)
{
Thread t3 = new Thread (delegate () {
UseMemory();
});
t3.Start ();
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = false;
timer.Interval = 1000;
timer.Start();
timers.Add(timer);
}
for (int i = 0; i < 4000; i++)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = false;
timer.Interval = 500;
timer.Start();
timers.Add(timer);
}
lock (count_lock)
{
while (count < num_threads)
{
Monitor.Wait(count_lock);
}
}
foreach (var t in threads)
{
t.Join();
}
}
}
}
|