-
Notifications
You must be signed in to change notification settings - Fork 583
Expand file tree
/
Copy pathKernel.cs
More file actions
79 lines (58 loc) · 1.96 KB
/
Copy pathKernel.cs
File metadata and controls
79 lines (58 loc) · 1.96 KB
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
using System;
using Sys = Cosmos.System;
using Cosmos.System;
using Cosmos.TestRunner;
using Console = System.Console;
namespace ThreadingTests
{
public class Kernel : Sys.Kernel
{
int variable = 0;
int variableTwo = 0;
int variableThree = 0;
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Let's Test Threading!");
}
protected override void Run()
{
try
{
var threadOne = new Thread(ThreadOne);
var threadTwo = new Thread(ThreadTwo);
threadOne.Start();
threadTwo.Start();
Console.WriteLine("Inside Run method!");
variableThree = 3;
//Since Run is not a thread call PIT wait
System.Threading.Thread.Sleep(3000);
//Cosmos.HAL.Global.PIT.Wait(3000);
Console.WriteLine("Waited 3 second.");
Assert.AreEqual(variable, 1, "Changing global variable from thread works");
Assert.AreEqual(variableTwo, 2, "Changing global variable from second thread works");
Assert.AreEqual(variableThree, 3, "Changing global variable from main context works");
TestController.Completed();
}
catch (Exception e)
{
mDebugger.Send("Exception occurred: " + e.Message);
mDebugger.Send(e.Message);
TestController.Failed();
}
}
public void ThreadOne()
{
//Make thread WAITING
Thread.Sleep(1000);
variable = 1;
Console.WriteLine("Inside first thread!");
}
public void ThreadTwo()
{
//Make thread WAITING
Thread.Sleep(1000);
variableTwo = 2;
Console.WriteLine("Inside second thread!");
}
}
}