-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME_HW1
40 lines (32 loc) · 2.17 KB
/
README_HW1
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
The Nachos runs from the main method of the Nachos.java.
After creation of the 'firstThread' and adding it to scheduler the control goes over to the
scheduler and program goes into the run() method of Nachos.java.
Inside run() method the program checks several flags from the Options.java class.
For this assignment I created 2 new flags-CYCLIC_BARRIER and TASK_MANAGER for each
of the two questions in the assignment. The flag which is set true gives a call to the demo()
methods to each of the class provided for this assignment-- CyclicBarrier.java and TaskManager.java.
In CyclicBarrier.java several threads are created and put to the nachos scheduler.
One by one these threads call the await method of the barrier.
The semaphore in the Cyclic barrier- sem2- keeps hold of each of these threads.
Only after a certain number of threads reach the barrier, the barrier is broken and threads
continue execution.
If reset is called by any thread, the barrier is broken and threads continue the execution.
In TaskManager.java
The execution starts in the method demo() of TaskManager.java which is called from run() of
Nachos.java.
Several child threads are created which are added to the scheduler.
These threads execute their doInBackground() method. Once completed the child threads
communicate to the parent thread about the completion of this method and the parent
thread begins the onCompletion/onCancellation -based on the flag isCancelled.
Also, the class- FindNumbersTask subclasses the class 'Task' and overrides the methods- doInBackground,
onCompletion and onCancellation. An object of this class is instantiated in the run method
of each of these child threads.
Also in the parent thread we maintain a queue of all child threads.
Each time a child thread is executed by the parent, the parent thread removes that
child thread object from the queue by calling the peek() method.
-----
To compile the code the required the jars - Machine.jar -must be present in the workspace and should be
entered into the classpath of the eclipse project.
The Machine.jar contains some important files such as NachosThread.java etc.
-----
To implement the Task Manager Qn I've used the synchronized block.