CS代考程序代写 algorithm jvm compiler scheme gui interpreter chain Java data structure flex concurrency Quiz -1 Assessed Coursework, Deadline 10:00am Tuesday 28/01/2020

Quiz -1 Assessed Coursework, Deadline 10:00am Tuesday 28/01/2020
Mark 10.00 out of
Question 1 Correct 10.00 Flag question
Select whether each of the following statements is true or false:
Aprocesscanmovedirectlyfromawaitingtoaterminatedstate False
If a process requests I/O it moves from a running state to a waiting state True A process can move directly from a waiting state to a ready state True Functionparametersarestoredinthestackofaprocess True Aprocessisanunchangingstaticcollectionofinstructions False
The correct answer is:
Select whether each of the following statements is true or false:
A process can move directly from a waiting to a terminated state [False]
If a process requests I/O it moves from a running state to a waiting state [True] A process can move directly from a waiting state to a ready state [True] Function parameters are stored in the stack of a process [True]
A process is an unchanging static collection of instructions [False]
Mark 10.00 out of
Question 2 Correct 10.00 Flag question
Schedule the following processes using first come first served scheduling:
P0 duration: 9 arrives: 13 priority: 13 P1 duration: 7 arrives: 14 priority: 14 P2 duration: 8 arrives: 0 priority: 0 P3 duration: 7 arrives: 1 priority: 1 P4 duration: 7 arrives: 5 priority: 5
What is the average turnaround time? Answer: 16.2
Correct! Well Done, you won’t need the hints below.
Hint: each process runs until it finishes, processes start in the order they arrived, see the lecture notes for more details The correct answer is: 16.2
Mark 8.33 out of
Question 3 Partially correct 10.00 Flag question
P1 (duration 13) P2 (duration 12) P3 (duration 5) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the
processes arrive in the order process if another process arrives. In once on a system is called
. In scheduling a the scheduler cannot choose to stop a running multiprocessing one processor does all the scheduling. Running more than one process at
.

Almost there…
You have correctly selected 5.
The correct answer is:
P1 (duration 13) P2 (duration 12) P3 (duration 5) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order [P3] [P2] [P1]. In [non-pre-emptive] scheduling a the scheduler cannot choose to stop a running process if another process arrives. In [asymmetric] multiprocessing one processor does all the scheduling. Running more than one process at once on a system is called [Multiprogramming].
Mark 15.00 out of Question 4 Correct 15.00
Flag question
Schedule the following processes using pre-emptive priority scheduling:
P0 duration: 13 arrives: 4 priority: 4 P1 duration: 5 arrives: 0 priority: 7
P2 duration: 3 arrives: 4 priority: 0
P3 duration: 3 arrives: 6 priority: 3
P4 duration: 12 arrives: 12 priority: 12
Fill in the schedule below:
Process P1
P2 P3 P0 P1 P4
Start Time Runs For 04
43 73 10 13 23 1 24 12
Now complete the waiting and turnaround times for each process, then the total and averages.
Process Waiting Time P0 6
P1 19
P2 0
P3 1 P4 12 Total 38 Average 7.6
Turnaround Time 19
24 3
4 24 74 14.8
The correct schedule is: 0: P1 (4)
4: P2 (3)
7: P3 (3)
10: P0 (13)
23: P1 (1)
24: P4 (12)
Waiting times: P0 6 P1 19 P2 0 P3 1 P4 12 Turnaround times : P1 24 P3 4 P4 24 P0 19 P2 3
Mark 15.00 out of Question 5 Correct 15.00
Flag question

Correct! Well done.
The correct answers are: Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling, Multi-queue scheduling can
be used on single processor systems., Multi-level feedback queues can be used for priority scheduling. Information Flag question
Information for answering Round Robin Scheduling Questions.
If you have a quantum of 3 for example, and a schedule like this: 0: P0 (3)
3: P0 (3)
6: P1 (3)
9: P2 (3) 12: P2 (1)
Then don’t enter it as above, with the original quanta, but rather include the total time each process is running, so: 0: P0 (6)
6: P1 (3)
9: P2 (4)
In your question there wouldn’t be enough boxes to do it the first way round.
Mark 13.47 out of
Question 6 Partially correct 15.00 Flag question
This question is about multi-queue scheduling. Select all the true statements from the list below:
Select one or more:
Multi-queue scheduling can be used on single processor systems. Correct!
Multi-level feedback queues can be used for priority scheduling. Correct!
Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling Correct! Another option is for higher priority queues to have absolute priority, using aging to prevent starvation.
In Multi-level feedback queue scheduling jobs always stay on the same queue. In multi-queue scheduling all queues must have the same scheduling algorithm.
Schedule the following processes using round robin scheduling with quantum 3:
P0 duration: 8 arrives: 8 P1 duration: 13 arrives: 0 P2 duration: 12 arrives: 14 P3 duration: 6 arrives: 4 P4 duration: 7 arrives: 7
Fill in the schedule below:
Process P1
P3 P1 P4 P0 P3
Start Time 06 63 93 12 3 15 3 18 3
Runs For

The correct schedule is: 0: P1 (6)
6: P3 (3)
9: P1 (3)
12: P4 (3)
15: P0 (3)
18: P3 (3)
21: P1 (3)
24: P2 (3)
27: P4 (3)
30: P0 (3)
33: P1 (1)
34: P2 (3)
37: P4 (1)
38: P0 (2)
40: P2 (6)
Waiting times: P0 24 P1 21 P2 20 P3 11 P4 24 Turnaround times : P1 34 P3 17 P0 32 P2 32 P4 31
Mark 7.50 out of
Question 7 Partially correct 10.00 Flag question
21 3
P2
P4 P0 P1 P2 P4 P0 P2
24 3
27 3 30 3 33 1 34 3 37 1 38 2 40 6
Now complete the waiting and turnaround times for each process, then the total and averages.
Process Waiting Time P0 24
P1 21
P2 2
P3 11 P4 24 Total 82 Average 16.4
Turnaround Time 32
34
14
17 31 128 25.6
P1
Select whether each of the following statements is true or false:

You have correctly selected 3.
The correct answer is:
Select whether each of the following statements is true or false:
SJF is a good algorithm for short-term scheduling as CPU burst lengths are easy to to predict [False]. Windows XP uses multi-level queue scheduling [True].
In Linux the priority of a non-real-time process is boosted if it is interactive. [True].
A child process always shares the resources of its parent [False].
Mark 15.00 out of
Question 8 Correct 15.00 Flag question
Schedule the following processes using shortest remaining time first scheduling:
P0 duration: 22 arrives: 11 P1 duration: 14 arrives: 0 P2 duration: 6 arrives: 15 P3 duration: 16 arrives: 29 P4 duration: 8 arrives: 24
Fill in the schedule below:
Process P1
P0 P2 P0 P4 P3 P0
Start Time 0
14 15 21 24 32 48
Runs For 14
1 6 3 8 16 18
Now complete the waiting and turnaround times for each process, then the total and averages.
Process Waiting Time P0 33
P1 0
P2 0
P3 3 P4 0 Total 36 Average 7.2
Turnaround Time 55
14 6 19 8 102 20.4
SJF is a good algorithm for short-term scheduling as CPU burst lengths are easy to to predict . WindowsXPusesmulti-levelqueuescheduling False .
In Linux the priority of a non-real-time process is boosted if it is interactive. True . Achildprocessalwayssharestheresourcesofitsparent False .
False

The correct schedule is: 0: P1 (14)
14: P0 (1)
15: P2 (6)
21: P0 (3)
24: P4 (8)
32: P3 (16)
48: P0 (18)
Waiting times: P0 33 P1 0 P2 0 P3 3 P4 0 Turnaround times : P2 6 P3 19 P4 8 P0 55 P1 14
Week 2 Quiz – Assessed Coursework, Deadline 10:00am 04/02/2020
Mark 10.00 out of
Question 1 Correct 10.00 Flag question
Select whether each of the following statements is true or false:
Ifathreadcallsyield()itisterminated False .
Java automatically creates a separate thread for a GUI to make sure it remains responsive True . When a Thread is created using the constructor it enters a runnable state False . AlineofJavacodeisexecutedonaCPUasasingleatomicinstruction False .
Congratulations!
The correct answer is:
Select whether each of the following statements is true or false:
If a thread calls yield() it is terminated [False].
Java automatically creates a separate thread for a GUI to make sure it remains responsive [True]. When a Thread is created using the constructor it enters a runnable state [False].
A line of Java code is executed on a CPU as a single atomic instruction [False].
Mark 20.00 out of
Question 2 Correct 20.00 Flag question
A programmer wrote the following code with the intention of creating a concurrent threaded program.
public class myMain {
public static void main(String[] args){ Thread q = new Printer(“Q”);
Thread p = new Printer(“P”); p.start();
q.start();
try{
p.join();
} catch (Exception e){
e.printStackTrace(); }
for(int i = 0; i < 10; ++i){ System.out.print(“R”); } } } The code for the class Printer is correctly implemented, the class extends Thread and the run method prints out the letter given as an argument to the constructor 10 times (it may, or may not, do other computation that does not produce any output). Which of the following are possible outputs of this program? (to save laborious counting you can safely assume that all answers contain 10Ps, 10Qs and 10Rs). The correct answer is: 1, 7, 6 and 4 only Mark 7.50 out of Question 3 Partially correct 10.00 Flag question Select whether each of the following statements is true or false: Inathreadedprogramonethreadmustfinishexecutingbeforeanothercanstart. False . There is no point in writing threaded code for a machine with only 1 CPU. False . Aprogramwithtwothreadswillruntwiceasfastasaprogramwithonethread,onanymachine. False . Ifeachindividualstatementinaconcurrentprogramisatomicthenthereisnocriticalsectionproblem. True . You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: In a threaded program one thread must finish executing before another can start. [False]. There is no point in writing threaded code for a machine with only 1 CPU. [False]. A program with two threads will run twice as fast as a program with one thread, on any machine. [False]. If each individual statement in a concurrent program is atomic then there is no critical section problem. [False]. Mark 15.00 out of Question 4 Correct 15.00 Flag question 0: QQQPPPQQPPQPPQQPQPQRPRRRRRRRRR 1: QQQQQQQQQQPPPPPPPPPPRRRRRRRRRR 2: RRRRRRRRRRPPPPPPPPPPQQQQQQQQQQ 3: QPRQPRQPRQPRQPRQPRQPRQPRQPRQPR 4: QQQPPPQQPPQPPQQPQPPRRQRRRRRRRR 5: PRPRPRPRPRPRPRPRPRPRQQQQQQQQQQ 6: QPQPQPQPQPQPQPQPQPQPRRRRRRRRRR 7: PPPPPPPPPPRRRRRRRRRRQQQQQQQQQQ 8: QRQRQRQRQRQRQRQRQRQRPPPPPPPPPP 9: QQQQQQQQQQRRRRRRRRRRPPPPPPPPPP Select one: None of the above. 1 only 1, 7, 6 and 4 only 1 and 6 only 1, 9, 6 and 0 only 1, 7, 6, 0 and 4 only 1, 9 and 8 only All of the above Correct! Since p.join() is called the main thread must wait for p to finish before continuing. In the following solution to the critical section problem (note that the two processes are slightly different): boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false Executionofthefollowinginterleaving:p0,q0,q1,p1,p2,q2wouldleadto violationofmutualexclusion . The correct answer is: In the following solution to the critical section problem (note that the two processes are slightly different): Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to [violation of mutual exclusion]. Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to [starvation of q]. This program satisfies the requirement for [Freedom From Deadlock]. It is [True] that p can never starve. Mark 10.00 out of Question 5 Correct 10.00 Flag question boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false If a single process is executing its preprotocol but is never able to enter its critical section this is called . To verify that a solution to the critical section problem is correct we must show that the condition. To verify that a solution to the critical section problem is incorrect we must show that the condition. Correct, well done! The correct answer is: If a single process is executing its preprotocol but is never able to enter its critical section this is called [starvation]. To verify that a solution to the critical section problem is correct we must show that [all interleavings satisfy] the condition. To verify that a solution to the critical section problem is incorrect we must show that [at least one interleaving breaks] the condition. Mark 20.00 out of Question 6 Correct 20.00 Flag question Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to . This program satisfies the requirement for Freedom From Deadlock . It is True that p can never starve. starvation of q Consider the following solution to the critical section problem: boolean wantp <- false, wantq <- false p q loop_forever p1: non-critical section p2: P3: p4: P5: p6: p7: wantp <- true while wantq wantp <- false wantp <- true critical section wantp <- false loop_forever q1: non-critical section q2: q3: q4: q5: q6: q7: wantq <- true while wantp wantq <- false wantq <- true critical section wantq <- false Which of the three properties does this solution satisfy? Select one: Mutual Exclusion Only. Freedom From Deadlock Only. Mutual Exclusion and Freedom From Starvation only. The correct answer is: Mutual Exclusion and Freedom From Deadlock only. Mark 15.00 out of Question 7 Correct 15.00 Flag question A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread p = new Printer("p"); Thread q = new Printer("Q"); p.run(); q.run(); for(int i = 0; i < 10; ++i){ System.out.println("R"); } } } What is the maximum number of threads belonging to this program running at any one time during its execution? Select one: 0 2 3 . 1 Correct! Although the programmer tried to start to threads they called run() instead of start(). This error meant that no new threads were created Further exercise: if the programmer had called start() how many processes would be running? The correct answer is: 1 Week 3 Quiz - Assessed Coursework, Deadline 10:00 am 11/02/2020 Mark 10.00 out of Question 1 Correct 10.00 Flag question Select whether each of the following statements is true or false: Starvation can occur in the bakery algorithm if a process exits in its non-critical section. False . Ticketnumbersinthebakeryalgorithmareunbounded. True . Thebakeryalgorithmisefficientforuseinpractice. False . If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twicewhilstphastowait. False . Congratulations! The correct answer is: Select whether each of the following statements is true or false: Starvation can occur in the bakery algorithm if a process exits in its non-critical section. [False]. Ticket numbers in the bakery algorithm are unbounded. [True]. The bakery algorithm is efficient for use in practice. [False]. Freedom From Deadlock and Freedom From Starvation only. Mutual Exclusion and Freedom From Deadlock only. Correct! Make sure you can give the scenario that leads to starvation. All Three: Mutual Exclusion, Freedom From Starvation, Freedom From Deadlock. Freedom From Starvation Only. None. If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twice whilst p has to wait. [False]. Mark 10.00 out of Question 2 Correct 10.00 Flag question Which of the following are valid outputs for the following program: Select one or more: qrp qpr rqp rpq Semaphore S1<- 0, S2 <- 0 p q r p1: print(“p”) p2: signal(S1) p3: signal(S2) q1: wait(S1) q2: print(“q”) r1: wait(S2) r2: print(“r”) pqr Correct! And there's at least one more. prq Good, that was the hard one, the scheduler might permit p1,p2,p3 and then schedule r. The correct answers are: pqr, prq Mark 20.00 out of Question 3 Correct 20.00 Flag question Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Solution1: MutualExclusionOnly Solution2: FreedomFromDeadlockOnly Solution3: FreedomFromDeadlockOnly Solution4: Both Solution5: FreedomFromDeadlockOnly The correct answer is: Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Solution 1: [Mutual Exclusion Only] Solution 2: [FreedomFrom Deadlock Only] Solution 3: [FreedomFrom Deadlock Only] Solution 4: [Both] Solution 5: [FreedomFrom Deadlock Only] Solution 6: [Mutual Exclusion Only] Solution 7: [Both] Solution 8: [Both] Mark 20.00 out of Question 4 Correct 20.00 Flag question Solution 6: Solution7: Both Solution8: Both Mutual Exclusion Only Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends Thread { staticSemaphore safeToCross= newSemaphore(2) ; private String name; public Pedestrian(String nameIn){ name = nameIn; } Your answer is correct. The correct answer is: Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends [Thread] { [static Semaphore] safeToCross = [new Semaphore(2)]; private String name; public Pedestrian(String nameIn){ name = nameIn; } [public void run()]{ for(int i = 0; i < 3; ++i){ try{ [safeToCross.acquire();] System.out.println("Pedestrian " + name + " Entering the Bridge"); [Thread.sleep(100);] System.out.println("Pedestrian " + name + " Leaving the Bridge"); [safeToCross.release();] { for(int i = 0; i < 3; ++i){ try{ safeToCross.acquire(); System.out.println("Pedestrian " + name + " Entering the Bridge"); Thread.sleep(100); System.out.println("Pedestrian " + name + " Leaving the Bridge"); safeToCross.release(); } catch ( InterruptedException e.printStackTrace(); } } } e){ public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave. start() ; Pedestrian pete = new Pedestrian("Pete"); pete. start() ; Pedestrian jackie = new Pedestrian("Jackie"); jackie. start() ; Pedestrian jane = new Pedestrian("Jane"); jane. start() ; } } public void run() } catch ([InterruptedException] e){ e.printStackTrace(); } } } public static void main(String[] args){ Pedestrian dave = dave.[start()]; Pedestrian pete = pete.[start()]; Pedestrian jackie jackie.[start()]; Pedestrian jane = jane.[start()]; } } new Pedestrian("Dave"); new Pedestrian("Pete"); = new Pedestrian("Jackie"); new Pedestrian("Jane"); Mark 10.00 out of Question 5 Correct 10.00 Flag question Select whether each of the following statements is true or false: Semaphoresaresoftwareandareusuallyprovidedbytheoperatingsystemkernel True . If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. True . Waitincreasesthevalueofthesemaphore'sintegervariable. False . Testandsetisprovidedbyhardware. True . Congratulations! The correct answer is: Select whether each of the following statements is true or false: Semaphores are software and are usually provided by the operating system kernel [True]. If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. [True]. Wait increases the value of the semaphore's integer variable. [False]. Test and set is provided by hardware. [True]. Mark 5.00 out of Question 6 Correct 5.00 Flag question Which of the three types of semaphore can be used to implement a solution to the critical section problem without the risk of starvation? Select one: None of them. Busy Wait Semaphores and Blocked Set Semaphores. Blocked Set semaphores only. All of them. Blocked Queue semaphores only. Correct! Busy Wait sempahores only. Blocked Queue and Blocked Set semaphores only. Busy Wait Semaphores and Blocked Queue Semaphores. The correct answer is: Blocked Queue semaphores only. Mark 15.00 out of Question 7 Correct 15.00 Flag question A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain specifies that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the floor). Complete the following pseudocode model of the problem: loop forever: loop forever: Semaphore CrateOnTrain <- , Semaphore spaceOnTrain <- 10 0 Loading Crane Unoading Crane pickup crate from floor wait(spaceOnTrain) load crate onto train signal(crateOnTrain) wait(crateOnTrain) unload crate from train signal(spaceOnTrain) put down crate on floor The correct answer is: A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain specifies that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the floor). Complete the following pseudocode model of the problem: Semaphore CrateOnTrain <- [10], Semaphore spaceOnTrain <- [0] Loading Crane Unoading Crane loop forever: [pickup crate from floor] [wait(spaceOnTrain)] [load crate onto train] [signal(crateOnTrain)] loop forever: [wait(crateOnTrain)] [unload crate from train] [signal(spaceOnTrain)] [put down crate on floor] Mark 10.00 out of Question 8 Correct 10.00 Flag question Consider the following solution to the dining philosophers problem in which five philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] The correct answer is: Consider the following solution to the dining philosophers problem in which five philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to [deadlock]. Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock [false]. Changing the order in which philosopher t picks up the forks will prevent deadlock [true]. Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock [true]. Week 4 Quiz - Assessed Coursework, Deadline 18/02/2020 @ 10am Mark 10.00 out of Question 1 Correct 10.00 Flag question Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) Theinterleavingp1,p2,q1,q2,r1,r2,s1,s2,t1,t2leadsto deadlock . Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock false . Changingtheorderinwhichphilosophertpicksuptheforkswillpreventdeadlock true . Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock true . loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) Consider the follow diagram representing the states of threads in Java when using monitors. StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) Runnable (c) Running (1) start() (2) run() The correct answer is: Consider the follow diagram representing the states of threads in Java when using monitors. StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) [Runnable] (c) [Running] (1) [start()] (2) [run()] (3) [yield()] (4) [wait()] (5) [notifyAll()] (6) [run() ends] The scheduler can cause transitions on edges [2 and 3]. Mark 20.00 out of Question 2 Correct 20.00 Flag question (3) (4) wait() (5) notifyAll() (6) run()ends Theschedulercancausetransitionsonedges 2and3 . yield() A programmer creates the following two Java classes: public class A { public synchronized void a1(){ //do something } public void a2(){ //do something } public synchronized int a3(){ int var = 0; //do something changing var return var; } } public class B { public void b1(){ //do something } public synchronized int b2(){ int var = 0; //do something changing var return var; } public void b3(){ //do something } } Then a main method which does the following: The correct answers are: secondA.a1() and secondA.a3(), secondA.a3() and secondA.a3() Mark 10.00 out of Question 3 Correct 10.00 Flag question Select whether each of the following statements is true or false: Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of theresource True . notify and wait can be called outside a monitor False . If we impose the immediate resumption requirement and use the classical monitor priority scheme (Entering < Notifying < Waiting) and notify a singlethreaditissafetouseiftocheckwaitconditions True . It is sometimes more efficient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run True . Congratulations! The correct answer is: Select whether each of the following statements is true or false: Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource [True]. notify and wait can be called outside a monitor [False]. If we impose the immediate resumption requirement and use the classical monitor priority scheme (Entering < Notifying < Waiting) and notify a single thread it is safe to use if to check wait conditions [True]. It is sometimes more efficient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run [True]. Mark 10.00 out of Question 4 Correct 10.00 Flag question The precise details of the creation and function of the threads are not important, so they are not given, you may assume that they run in parallel and call methods on the created objects. Further you may assume that no other mechanisms that are not shown prevent methods from running concurrently. Which of the following groups of methods cannot be run concurrently (i.e. will be sequenced so that one finishes before the other starts) if called at the same time by two different threads? Select one or more: secondA.a1() and firstB.b3() firstA.a2() and secondA.a2() firstA.a2() and firstA.a2() secondA.a3() and secondA.a3() Synchronized methods in the same object cannot be run in parallel, and that includes with themselves, the keyword synchronized requires one to complete before the other starts. Two different threads can attempt to call the same method at once, think for example, of two producers calling produce at the same time secondA.a1() and secondA.a2() firstB.b1() and firstB.b3() firstA.a2() and secondA.a3() firstA.a3() and secondA.a3() secondA.a1() and secondA.a3() Synchronized methods in the same object cannot be run in parallel, the keyword synchronized requires one to complete before the other starts secondA.a3() and firstB.b2() firstA.a2() and firstB.b1() public static void main(String[] args){ A firstA = new A(); A secondA = new A(); B firstB = newB(); //create some threads that perform operations on firstA, secondA and first B and start them } Congratulations! The correct answer is: This question is about Java programming using swing. Select whether each of the following statements is true or false: Concurrency bugs can only ever occur when the programmer exlicitly creates a thread. [False]. Methods running in the event dispatch thread cannot access data structures created in the main thread. [False]. It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. [False]. Threading problems cannot occur when using swing because it is thread safe. [False]. Mark 10.00 out of Question 5 Correct 10.00 Flag question This question is about Java programming using swing. Select whether each of the following statements is true or false: Concurrencybugscanonlyeveroccurwhentheprogrammerexlicitlycreatesathread. False . Methods running in the event dispatch thread cannot access data structures created in the main thread. False . It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. False Threading problems cannot occur when using swing because it is thread safe. False . . Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. Your answer is correct. The correct answer is: Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. 1: public class CrossingUser extends Thread { 2: private String mode; 3: private Crossing crossing; 4: 5: public CrossingUser(Crossing toUse, String modeIn){ 6: 7: 8: 9: 10: 11: crossing.enterCrossing(this); 12: crossing.useCrossing(this); 13: crossing.leaveCrossing(this); 14: } 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: public int timeToCross(){ if(mode.equals("ROAD")){ return 50; } else { return 200; } } public String getMode(){ return mode; } } mode = modeIn; crossing = toUse; } public void run(){ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 13: 13: 14: public class Crossing { private String mode = ""; private int users = 0; public synchronized void enterCrossing(CrossingUser u){ while !u.getMode().equals(mode) try{ } catch ( InterruptedException e.printStackTrace(); } } mode = u.getMode() ; ( !mode.equals("") ){ && e){ wait() ; 15: 16: Crossing"); 17: } 18: ++users; System.out.println(u.getMode() + " User Entering the public void 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: } Crossing"); 34: notifyAll() ; 35: } 36: } useCrossing(CrossingUser u){ Thread.sleep(u.timeToCross()) ; try{ } catch ( InterruptedException e){ e.printStackTrace(); } } public synchronized void --users; if(users == 0){ leaveCrossing(CrossingUser u){ ; System.out.println(u.getMode() + " User Leaving the 32: 33: mode = "" Mark 10.00 out of Question 6 Correct 10.00 Flag question Now the following rules are to be enforced: It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2); No more than 1 road user can be on the crossing at the same time (restriction 3). Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You're answer will not be marked as correct unless you complete the restrictions in the specified order (this is a limitiation of KEATS, of course any order of the conditions would work in Java). while //restriction 1 //restriction 2 try {//etc. } ((!u.getMode().equals(mode) && (users>2 && (users>0 &&
!mode.equals(“”) u.getMode().equals(“FOOT”) u.getMode().equals(“ROAD”)
) || ) ||
)){ //restriction3
Your answer is correct.
The correct answer is:
Now the following rules are to be enforced:
It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2);
No more than 1 road user can be on the crossing at the same time (restriction 3).
1: public class CrossingUser extends Thread {
2: private String mode;
3: private Crossing crossing; 4:
5: public CrossingUser(Crossing toUse, String modeIn){
6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
mode = modeIn;
crossing = toUse; }
public void run(){ crossing.enterCrossing(this); crossing.useCrossing(this); crossing.leaveCrossing(this);
}
public int timeToCross(){ if(mode.equals(“ROAD”)){
return 50; } else {
return 200; }
}
public String getMode(){
return mode; }
}
1: public class Crossing { 2:
3: private String mode = “”; 4: private int users = 0;
5:
6: [public synchronized void] enterCrossing(CrossingUser u){
7: [while]([!mode.equals(“”) ] [&&] [!u.getMode().equals(mode)]){
8:
9:
10:
11:
13:
13:
14:
15:
16:
the
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27: leaveCrossing(CrossingUser u){ 28:
29: 30: 31: 32: 33: the 34: 35: 36:
–users; if(users == 0){
[mode = “”]; }
System.out.println(u.getMode() + ” User Leaving Crossing”);
[notifyAll()]; }
}
Crossing”); }
}
e.printStackTrace(); }
try{ [wait()];
} catch ([InterruptedException] e){
[mode = u.getMode()];
++users;
System.out.println(u.getMode() + ” User Entering
[public void] useCrossing(CrossingUser u){ try{
[Thread.sleep(u.timeToCross())]; } catch ([InterruptedException] e){
e.printStackTrace(); }
}
[public synchronized void]

Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You’re answer will not be marked as correct unless you complete the restrictions in the specified order (this is a limitiation of KEATS, of course any order of the conditions would work in Java).
[while](([!u.getMode().equals(mode)] [&&] [!mode.equals(“”) ] ) [||] //restriction 1 ([users > 2] [&&] [u.getMode().equals(“FOOT”)]) [||] //restriction 2 ([users > 0] [&&] [u.getMode().equals(“ROAD”)])){ //restriction 3
try {//etc. }
Question 7
Mark 15.00 out of
Correct 15.00 Flag question
Consider the following method (and class variables), that are intended to enforce the following rules:
The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once;
Only one car can travel westbound at once.
int carCount = 0;
boolean westbound = false;
public synchronized void enterBridge(Vehicle v){ //block
westbound = v.getWestbound(); //set direction to your direction ++carCount; //increment cars using bridge
System.out.println(v + “ entering the bridge”);
}
Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of
the code is correctly implemented.
block 1:
while((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 2:
while((v.getWestbound() != westbound && carCount > 0) &&
(!v.getWestbound() && carCount > 2) && (v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 3:
if((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 4:
if((v.getWestbound() != westbound && carCount > 0)) {
if (!v.getWestbound() && carCount > 2) { if (v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}

The correct answer is: block 1
Mark 15.00 out of
Question 8 Correct 15.00 Flag question
} }
}
block 5:
if((v.getWestbound() != westbound && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
if(!v.getWestbound() && carCount > 2) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
block 6:
while((v.getWestbound() != westbound && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
while(!v.getWestbound() && carCount > 2) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
while(v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
Select one or more:
b. block 2 c. block 3 d. block 4 e. block 5 f. block 6
a. block 1 Correct!
Consider the following methods to exit and cross the bridge that are to be a part of the same class as the previous enterBridge method.
public synchronized void exitBridge(Vehicle v){ –carCount;
System.out.println(v + “ exiting the bridge”); notifyAll();
}
public void crossBridge(){ try{
Thread.sleep(100);
} catch (InterruptedException e){
e.printStackTrace();

The correct answers are: Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one., Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock., If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should.
Week 5 Quiz – Assessed Coursework, Deadline 10:00am 25/02/2019
Mark 15.56 out of
Question 1 Partially correct 20.00 Flag question
} }
Select all statements that are correct: Select one or more:
No threads will be needlessly blocked if notifyAll() is replaced with notify()
If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should.
would each have to wait in turn to execute crossBridge, and could therefore not be sleeping at the same time.
Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one. Correct!
Correct! The threads
Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock. Correct! No cars would be able to enter the bridge once three had entered because they would wait indefintely for car count to be low enough.
If the order of the println and notifyAll statements are swapped it is possible that another car will enter the bridge before the message exiting the bridge is printed.
For each of the following scenarios use the Banker’s algorithm to determine whether the system is in a safe or an unsafe state. If the system is safe, give the safe order that Banker’s algorithm would produce for the processes (you should assume that ties are broken by selecting the process with the smallest number when multiple processes are able to run). If the system is not in a safe state, give the order processes that have executed were executed in, and fill the remaining boxes with X. All allocations and requirements are specified for three resources in the order R1, R2, R3.
Scenario 1:
P0 max requirement 0,0,4 and allocation 0,0,1. P1 max requirement 1,4,1 and allocation 0,3,0. P2 max requirement 0,2,4 and allocation 0,0,1. P3 max requirement 0,0,4 and allocation 0,0,1. P4 max requirement 4,4,1 and allocation 2,0,0.
The current resource availability is:2,1,1. The system is in a Unsafe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P1 P4 X X X
Scenario 2:
P0 max requirement 3,1,4 and allocation 0,0,3. P1 max requirement 0,4,7 and allocation 0,2,3. P2 max requirement 0,3,1 and allocation 0,0,0. P3 max requirement 2,1,1 and allocation 1,0,0. P4 max requirement 3,3,4 and allocation 0,1,0.
The current resource availability is:2,1,1. The system is in a Safe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P3 P0 P1 P2 P4 Scenario 3:
P0 max requirement 4,1,0 and allocation 2,0,0. P1 max requirement 8,1,0 and allocation 0,0,0. P2 max requirement 3,4,0 and allocation 1,2,0. P3 max requirement 3,0,0 and allocation 1,0,0. P4 max requirement 0,2,4 and allocation 0,0,1.

Mark 7.50 out of
Question 2 Partially correct 10.00 Flag question
Select whether each of the following statements is true or false:
Deadlockcannotoccurifthereareonlytwoprocessesrunning False .
Deaclock can occur if there is no circular wait False .
Ifthesystemisinanunsafestatethendeadlockhasoccured True .
It is realistic to assume that we know the resource requirements of all processe up front in a modern operating system False .
You have correctly selected 3.
The correct answer is:
Select whether each of the following statements is true or false:
Deadlock cannot occur if there are only two processes running [False].
Deaclock can occur if there is no circular wait [False].
If the system is in an unsafe state then deadlock has occured [False].
It is realistic to assume that we know the resource requirements of all processe up front in a modern operating system [False].
Mark 10.00 out of
Question 3 Correct 10.00 Flag question
The current resource availability is:4,2,3. The system is in a Safe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P0 P2 P3 P1 P4
Consider the following code:
public class myFirstThread extends Thread {
Semaphore s1,s2,s3;
public myFirstThread(Semaphore a, Semaphore b,
s1 = a; s2 = b; s3 = c;
}
public void run(){
Semaphore c){
//first thread implementation }
}
public class mySecondThread extends Thread {
Semaphore s1,s2,s3;
public mySecondThread (Semaphore a, Semaphore b,
s1 = a; s2 = b; s3 = c;
}
public void run(){
Semaphore c){
//second thread implementation }
}
public
}
static void main(String[] args){
Semaphore s1 = new Semaphore(1); Semaphore s2 = new Semaphore(2); Semaphore s3 = new Semaphore(1);
Thread t1 = new myFirstThread(s1,s2,s3); Thread t2 = new mySecondThread(s1,s2,s3); t1.start();
t2.start();
Which of the following pairs of implementations of the run methods can deadlock? Exception handling code (try, catch) has been omitted for clarity.
first thread implementation
second thread implementation

a
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s2.release();
}
b
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s1.acquire(); s3.acquire(); s3.release(); s1.release();
}
c
public void run(){ s1.acquire(); s3.release();
}
public void run(){ s3.acquire(); s1.release();
}
d
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
e
public void run(){ s1.acquire(); s1.release();
}
public void run(){ s3.acquire(); s3.release();
}
f
public void run(){ s2.acquire(); s1.acquire(); s1.release(); s2.release();
}
public void run(){ s1.acquire(); s2.acquire(); s2.release(); s1.release();
}
g
public void run(){ s1.acquire(); s3.acquire(); s1.release(); s3.release();
}
Select one or more:
c d e f g
public void run(){ s1.acquire(); s1.release();
}
a Correct! Since s1 is not signalled by t2 after being acquired it will become zero and both threads could end up waiting for it. b What happens if t1 acquires s1 then t2 acquires s3?
The correct answers are: a, b
Mark 3.33 out of
Question 4 Partially correct 10.00 Flag question

The correct answers are: This program will almost certainly deadlock if ran for long enough., If the keyword synchronized was removed from the addItem method the program could not deadlock., If the keyword synchronized was removed from the addItem method loss of data could occur.
Mark 10.00 out of
Question 5 Correct 10.00 Flag question
Consider the following concurrent program:
Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 LeadstoDeadlock .
p1,p2,p3,q1,q2,q3 Does not Necessarily Lead to Deadlo.ck p1,p2,q1,q2,p3,q3 LeadstoDeadlock . p1,q1,p2,p3,q2,q3 Does not Necessarily Lead to Deadlo.ck
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Select one or more: a. This program is guaranteed to deadlock. b. This program will almost certainly deadlock if ran for long enough. c. This program is unlikely to deadlock in a short time period. d. This program can never deadlock. e. If the keyword synchronized was removed from the addItem method the program could not deadlock. f. If the keyword synchronized was removed from the addItem method loss of data could occur. public class Buffer { ArrayList messages;
public Buffer(){
messages = new ArrayList(); messages.add(“Hello”); messages.add(“World”);
}
public synchronized void moveFirstItemTo(Buffer other){
if(!messages.isEmpty()){
other.addItem(messages.remove(0)); }
}
public synchronized void addItem(String message){
messages.add(message); }
}
public class BufferUser extends Thread { Buffer b1;
Buffer b2;
public BufferUser(Buffer firstBuffer, Buffer secondBuffer){
b1 = firstBuffer;
b2 = secondBuffer; }
public void run(){ while(true){
b1.moveFirstItemTo(b2); }
} }
public static void main(String[] args) { Buffer b1 = new Buffer();
Buffer b2 = new Buffer();
BufferUser t1 = new BufferUser(b1,b2);
BufferUser t2 = new BufferUser(b2,b1);
t1.start();
t2.start(); }

The correct answer is:
Consider the following concurrent program:
Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 [Leads to Deadlock].
p1,p2,p3,q1,q2,q3 [Does not Necessarily Lead to Deadlock].
p1,p2,q1,q2,p3,q3 [Leads to Deadlock].
p1,q1,p2,p3,q2,q3 [Does not Necessarily Lead to Deadlock]. Mark 5.00 out of
Question 6 Partially correct 10.00 Flag question
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false The number of possible interleavings of i threads (assuming all interleavings are valid) is given by the formula: (n1+n2 + ... + ni)!/(n1!*n2!*...*ni!)) where ni is the number of atomic instructions in thread i. Assuming each line of the following program represents an atomic instruction complete the following statement: There are 20 possible interleavings of this program of which 6 lead to deadlock. boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Mark 3.33 out of Question 7 Partially correct 20.00 Flag question For each of the following scenarios use the Banker's algorithm to determine whether the system is deadlocked. If the system is deadlocked, give the processes involved in the deadlock; if not set all to X. All allocations and requests are specified for three resources in the order R1, R2, R3. Scenario 1: P0 requested 0,0,0 and allocation 0,0,0. P1 requested 0,0,0 and allocation 0,0,0. P2 requested 2,1,2 and allocation 1,0,2. P3 requested 0,2,0 and allocation 0,0,0. P4 requested 1,2,1 and allocation 1,0,1. The current resource availability is: 0,2,0. Thesystemis Deadlocked . The following processes are deadlocked (enter X if the process is NOT deadlocked): P0 P1 X P3 X Scenario 2: P0 requested 0,0,0 and allocation 1,0,0. P1 requested 1,1,0 and allocation 0,0,1. P2 requested 0,1,0 and allocation 0,1,0. P3 requested 2,2,1 and allocation 0,0,1. P4 requested 0,0,2 and allocation 1,1,0. The current resource availability is: 0,1,0. Thesystemis Deadlocked Mark 10.00 out of Question 8 Correct 10.00 Flag question Which of the following resource allocation graphs represent a deadlocked system? a b c d Select one: a, c and d only. a, b and d only. All of them. b and d only. None of them. b. c and d only. d only. a and b only. c and d only The correct answer is: c and d only Week 6 Quiz - Deadline 10:00 am on Tuesday 03/3/2020 Mark 5.00 out of Question 1 Correct 5.00 Flag question Your answer is correct. The correct answer is: compile-time binding Absolute code can be generated for : Select one: a. load-time binding b. compile-time binding c. excution-time binding d. interrupt binding . The following processes are deadlocked (enter X if the process is NOT deadlocked): P0 P1 P2 X X Scenario 3: P0 requested 1,0,0 and allocation 1,1,0. P1 requested 1,2,1 and allocation 0,0,1. P2 requested 1,2,0 and allocation 0,0,1. P3 requested 0,0,1 and allocation 0,0,0. P4 requested 1,1,1 and allocation 0,0,0. The current resource availability is: 1,1,0. Thesystemis NotDeadlocked . The following processes are deadlocked (enter X if the process is NOT deadlocked): P0 P1 P2 P3 P4 Mark 5.00 out of Question 2 Correct 5.00 Your answer is correct. The correct answer is: Execution time binding Mark 5.00 out of Question 3 Correct 5.00 Flag question ---------------------- is the method of binding instructions and data to memory performed by most general-purpose operating systems. Select one: a. Interrupt binding b. Compile time binding c. Execution time binding d. Load-time binding Flag question Suppose a program is operating with execution-time binding and the physical address generated is 300. The relocation register is set to 100. What is the corresponding logical address? Select one: a. 199 b. 200 c. 100 d. 300 Your answer is correct. The correct answer is: 200 Mark 5.00 out of Question 4 Correct 5.00 Your answer is correct. The correct answer is: memory-management-unit (MMU) Mark 5.00 out of Question 5 Correct 5.00 Flag question The mapping of a logical address to a physical address is done in hardware by the ________. Select one: a. relocation register b. dynamic loading register c. memory-management-unit (MMU) d. memory address register Flag question _____ is the dynamic storage-allocation algorithm which results in the smallest leftover hole in memory. Select one: a. Best fit b. Worst fit c. None of the options d. First fit Your answer is correct. The correct answer is: Best fit Mark 5.00 out of Question 6 Correct 5.00 Flag question The roll out, roll in variant of swapping is used ____. Select one: a. when a backing store is not necessary b. when the load on the system has temporarily been reduced c. for priority-based scheduling algorithms d. for the round-robin scheduling algorithm Your answer is correct. The correct answer is: for priority-based scheduling algorithms Mark 3.33 out of Question 7 Partially correct 5.00 Flag question This question is about contiguous memory allocation, where memory is divided into used and unused blocks of memory, of varying sizes. Which of the following statements about contiguous memory allocation are true: Select one or more: b. In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100. c. When using contiguous memory allocation for processes, compaction can be used to fix external fragmentation Correct! By moving processes from one memory location to another, we can get rid of the fragmentation between blocks of allocated memory. d. Round-robin scheduling relies on contiguous memory allocation a. Contiguous memory allocation suffers from external fragmentation Correct! The correct answers are: Contiguous memory allocation suffers from external fragmentation, In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100., When using contiguous memory allocation for processes, compaction can be used to fix external fragmentation Mark 10.00 out of Question 8 Correct 10.00 Flag question Consider the following Java code: 1325: public class SomeCode { 1326: public static int v = 9; 1327: public static int w = 4; 1328: public static void a() { 1329: int t = 7; 1330: v = v + t; 1331: t = t * 2; 1332: w = w + t; 1333: b(t); 1334: System.out.println(v + w); 1335: } 1336: public static void b(int param) { 1337: int s = 9; 1338: for (int i = 0; i < 3; ++i) { 1339: s = s + param; 1340: } Mark 2.50 out of Question 9 Partially correct 5.00 Flag question The correct answers are: Paging is based on diving memory into frames, the size of which are a power of two, When using paging, logical addresses are split into a page number, and an offset Mark 10.00 out of Question 10 Correct 10.00 Flag question Which of the following statements about paged memory allocation are true? Select one or more: a. Every call to 'new' requests another frame of memory, to store the resulting object. b. When using paging, logical addresses are split into a page number, and an offset d. Using paging can lead to external fragmentation between frames of allocated memory. c. Paging is based on diving memory into frames, the size of which are a power of two Correct! (The power of two bit is important.) 1341: v = v + 1; 1342: // What is on the stack here? 1343: } What is printed to the screen when this code executes? 35 What values are on the stack when execution reaches line 1342? Start filling in these boxes at the right hand side -- i.e. the item on the bottom of the stack goes in the rightmost box. If there are more boxes than you need, then fill the spare left-hand boxes with 0. Note, you should enter the values of variables on the stack, not their names; and you don't need to include the 'args[]' passed to main(). 0 0 0 51 1334 14 14 1348 42 1344: public static void main(String[] args) { 1345: int douglas = 40; 1346: douglas = douglas + 2; 1347: a(); 1348: System.exit(0); 1349: } 1350: } For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; •Ifintvariablesare32bits,whatisthesizeofobjectofthisclass,inbytes? 12 The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } •Atthispoint,howmuchmemoryisusedtostoreCoordinateobjects? 216 • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to storeMemoryControlBlocks? 288 Your answer is correct. The correct answer is: For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? [12] The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? [216] • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? [288] Mark 0.00 out of Question 11 Incorrect 5.00 Flag question Hashed page tables are particularly useful for processes with sparse address spaces. Select one: a. TRUE b. FALSE Your answer is incorrect. The correct answer is: TRUE Mark 5.00 out of Question 12 Correct 5.00 Flag question _____ is the dynamic storage-allocation algorithm which results in the largest leftover hole in memory. Select one: a. None of the above b. Worst fit c. First fit d. Best fit Your answer is correct. The correct answer is: Worst fit Mark 5.00 out of Question 13 Correct 5.00 Flag question Assume a system has a TLB hit ratio of 90%. It requires 15 nanoseconds to access the TLB, and 85 nanoseconds to access main memory. What is the effective memory access time in nanoseconds for this system? Select one: a. 22 b. 100 c. 176.4 d. 108.5 Your answer is correct. The correct answer is: 108.5 Mark 5.00 out of Question 14 Correct 5.00 Flag question Consider a logical address with 18 bits used to represent an entry in a conventional page table. How many entries are in the conventional page table? Select one: a. 1024 b. 18 c. 262144 d. 1048576 Your answer is correct. The correct answer is: 262144 Mark 5.00 out of Question 15 Correct 5.00 Flag question Assume the value of the base and limit registers are 1200 and 350 respectively. Which of the following addresses is legal? Select one: a. 1551 b. all of the above c. 355 d. 1200 Your answer is correct. The correct answer is: 1200 Mark 5.00 out of Question 16 Correct 5.00 Flag question What is the context switch time, associated with swapping, if a disk drive with a transfer rate of 2 MB/s is used to swap out part of a program that is 200 KB in size? Assume that no seeks are necessary and that the average latency is 15 ms. The time should reflect only the amount of time necessary to swap out the process. Select one: a. 120 ms b. None of the options Your answer is correct. The correct answer is: 113 ms Mark 5.00 out of Question 17 Correct 5.00 Flag question What is the advantage of using dynamic loading? Select one: a. dynamic loading allows the system to obtain better memory-space utilization b. With dynamic loading a program does not have to be stored, in its entirety, in main memory c. All of the options are correct d. dynamic loading allows unused routines to stay out of main memory so that memory can be used more effectively Your answer is correct. The correct answer is: All of the options are correct Mark 0.00 out of Question 18 Incorrect 5.00 Flag question A relocation register is used to check for invalid memory addresses generated by a CPU. Select one: a. TRUE b. FALSE Your answer is incorrect. The correct answer is: FALSE Information Flag question This is the end of the quiz questions - submit your work when you are happy. Remember, once you have pressed submit, you cannot change your answers. Week 7 Coursework - KEATS Quiz, Deadline 10:00 am Tuesday 10/03/2020 Mark 20.00 out of Question 1 Correct 20.00 Flag question c. 100 ms d. 113 ms A 32-bit computer has a virtual-memory space of 2^32 bytes. The computer is using memory paging, and the page size is 2^8 (i.e. 256) bytes. How many bits of the memory address are used for the page number? 24 How many bits of the memory address are used for the offset? 8 If each physical memory address is stored in 32-bits (i.e. 2^2 bytes), how large is the page table, in bytes? Give your answer as a power of two - e.g. if your answer is (2^10), then enter 10 into the box. Mark 20.00 out of Question 2 Correct 20.00 Flag question Information Flag question Thrashing is bad, m'kay. But which of the following would the situation worse, better, or have no effect at all? Mark 5.00 out of Question 3 Correct 5.00 Flag question The correct answer is: Have no effect on the amount of thrashing Mark 5.00 out of Consider a system with 3 frames of memory and the following sequence of page accesses: 1, 2, 3, 2, 3, 1, 2, 1, 3, 2, 1, 2, 0, 3, 1 When do page faults occur using the FIFO and LRU page replacement algorithms? Enter your answer as a string, comprising the letters Y and N, where Y means there was a page fault, and N means there was not. For instance, if you think there were three page faults to start with, and then no page faults after that, enter YYYNNNNNNNNNNNN Do not include any spaces or punctuation in your answer. FIFO Page faults: YYYNNNNNNNNNYNY LRU Page faults: YYYNNNNNNNNNYYY Adding a bigger hard drive will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing c. Have no effect on the amount of thrashing Correct - a bigger hard drive would have more free space, but the bottleneck is the time taken to swap pages to/from disk. Question 4 Correct 5.00 The correct answer is: Reduce the amount of thrashing Mark 5.00 out of Question 5 Correct 5.00 Flag question Terminating some processes (closing some programs) will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we terminate some processes, then memory is freed up, reducing the amount of thrashing. c. Have no effect on the amount of thrashing Flag question Adding more memory to the machine will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - adding more memory increases how much memory each process can use, reducing the number of page faults, and hence reducing thrashing. c. Have no effect on the amount of thrashing The correct answer is: Reduce the amount of thrashing Page table size = 2^ 26 bytes. Mark 5.00 out of Question 6 Correct 5.00 The correct answer is: Reduce the amount of thrashing Mark 5.00 out of Question 7 Correct 5.00 Flag question Rewriting code to have a smaller working set (locality) will: Select one: a. Increase the amount of thrashing c. Have no effect on the amount of thrashing b. Reduce the amount of thrashing Correct - if we can get the total working set size to be less than the amount of physical memory in the machine, we can hope to eliminate thrashing. Flag question In systems that support virtual memory, ____. Select one: a. virtual memory is separated from physical memory. b. physical memory is separated from secondary storage. c. physical memory is separated from logical memory. d. virtual memory is separated from logical memory. Your answer is correct. The correct answer is: physical memory is separated from logical memory. Question 8 Correct Mark 10.00 out of 10.00 Flag question Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what is the number of page faults for the given reference string? Select one: 8 10 13 14 Your answer is correct. The correct answer is: 8 Question 9 Correct Mark 10.00 out of 10.00 Flag question Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what will be the final configuration of the three frames following the execution of the given reference string? Select one: a. 3, 1, 4 b. 3, 4, 2 c. 4, 1, 3 d. 4, 2, 3 Your answer is correct. The correct answer is: 3, 4, 2 Mark 5.00 out of Question 10 Correct 5.00 Flag question Your answer is correct. The correct answer is: for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases Mark 5.00 out of Question 11 Correct 5.00 Flag question Belady's anomaly states that ____. Select one: a. as the number of allocated frames increases, the page-fault rate may decrease for all page replacement algorithms b. giving more memory to a process will improve its performance c. for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases d. for some page replacement algorithms, the page-fault rate may decrease as the number of allocated frames increases Optimal page replacement ____. Select one: requires that the system keep track of previously used pages is the page-replacement algorithm most often implemented can suffer from Belady's anomaly is used mostly for comparison with other page-replacement schemes Your answer is correct. The correct answer is: is used mostly for comparison with other page-replacement schemes Mark 5.00 out of Question 12 Correct 5.00 Flag question _____ is the algorithm implemented on most systems. Select one: LRU FIFO Least frequently used Most frequently used Your answer is correct. The correct answer is: LRU Week 8 Coursework - Deadline: 10:00, 20th of March 2020 Mark 5.00 out of Question 1 Correct 5.00 Flag question Which of the following two statements are security problems that can arise and need to be protected against when users simultaneously share a computing system -- i.e. they would not otherwise be an issue on a single-user system Select one or more: The correct answers are: One user's process might access the memory of another user's process, Confidential files kept on disk could be accessed by any user Mark 5.00 out of Question 2 Correct 5.00 Flag question Your answer is correct. The correct answer is: An advantage of compiler-based enforcement of access control is[access] privileges are closely related to the [linguistic ] concept of a data type. Mark 0.00 out of Question 3 Incorrect 5.00 Flag question Your answer is incorrect. The correct answer is: The [users] normally decide the contents of the access-matrix entries. Mark 2.50 out of Question 4 Partially correct 5.00 Flag question Your answer is partially correct. You have correctly selected 2. The correct answer is: The [access matrix] provides an appropriate mechanism for defining and implementing [strict control] for both the [static] and [dynamic] association between processes and domains. Mark 5.00 out of Question 5 Correct 5.00 Flag question Your answer is correct. The correct answer is: it is difficult to take advantage of special groupings of objects or domains when implementing [access matrix] using a [global table] Anadvantageofcompiler-basedenforcementofaccesscontrolisaccess privilegesarecloselyrelatedtothe linguistic concept of a data type. The operatingsystem normallydecidethecontentsoftheaccess-matrixentries. The accessmatrix providesanappropriatemechanismfordefiningandimplementing strictcontrol forboththe dynamic and static associationbetweenprocessesanddomains. itisdifficulttotakeadvantageofspecialgroupingsofobjectsordomainswhenimplementing accessmatrix usinga global table c. Users can accidentally delete their files from disk d. The system might start to run unacceptably slowly a. Confidential files kept on disk could be accessed by any user It's important to use access control to ensure users can have private files that only they (and systems administrators) can access. b. One user's process might access the memory of another user's process Yes, in principle, if one user's process accessed the memory of another user's process, it could, for instance, look at what document they were currently editing. Mark 0.00 out of Question 6 Incorrect 5.00 Flag question Your answer is incorrect. The correct answer is: Process P should be able to switch from domain Di to domain Dj if and only if the [access right] [switch ] ∈ access(i, j). Mark 4.00 out of Question 7 Correct 4.00 Flag question Your answer is correct. The correct answer is: The [copy and owner] rights allow a process to change the entries in a column in the access matrix and the [control ] rights applicable to [domain] objects only. Mark 5.00 out of Question 8 Correct 5.00 Flag question Your answer is correct. The correct answer is: The [capability] list is a [protected ]object maintained by [operating system ]and accessed by [users] only [indirectly]. Mark 3.33 out of Question 9 Partially correct 5.00 Flag question Your answer is partially correct. You have correctly selected 2. The correct answer is: Most systems use a combination of [access list and capabilities ] . When a process first tries to access an object, the [access list ] is searched. If access is denied, an exception condition occurs. Otherwise, a [capability ] is created and attached to the process. Mark 3.00 out of Question 10 Correct 3.00 Flag question Process P should be able to switch from domain Di to domain Dj if and only if the switch transfer right ∈ access(i, j). The copyandowner rightsallowaprocesstochangetheentriesinacolumnintheaccessmatrixandthe control rightsapplicableto domain objectsonly. The capability list is a protected object maintained by operating system and accessed by users only indirectly . Mostsystemsuseacombinationof globaltableandcapabilities .Whenaprocessfirsttriestoaccessanobject,the accesslist issearched.Ifaccessisdenied,anexceptionconditionoccurs.Otherwise,a capability is created and attached to the process. Enforcementby programminglanguages is more flexible thanenforcementbythe kernel for user-defined policy Your answer is correct. The correct answer is: Enforcement by [kernel ] is [less] [flexible] than enforcement by the [programming languages ] for user-defined policy Comment: Mark 2.40 out of Question 11 Partially correct 3.00 Flag question Your answer is partially correct. You have correctly selected 4. The correct answer is: In [Java], when a class is [loaded], the [JVM] assigns the class to a [protection ] domain that gives the [permissions ] of that class. Mark 5.00 out of Question 12 Correct 5.00 Flag question Your answer is correct. The correct answer is: A[confinement] problem is the problem of [ guaranteeing] that no [information] initially held in an [object] can migrate outside of its execution environment. Mark 5.00 out of Question 13 Correct 5.00 Flag question Your answer is correct. The correct answer is: The principle of least [privileges] means that programs, users, and even systems be given [just enough] privileges to perform their [tasks]. Mark 5.00 out of Question 14 Correct 5.00 Flag question In Java , when a class is loaded , the JVM assigns the class to a initiated domain that givesthe permissions ofthatclass. Aconfinement problemistheproblemof guaranteeing thatno information initiallyheldinan object can migrate outside of its execution environment. The principle of least privileges means that programs, users, and even systems be given just enough privileges to perform their tasks . Windows 2000 has a complex protection scheme at its core and yet has many security holes. Your answer is correct. The correct answer is: [Windows 2000] has a complex protection scheme at its core and yet has many security holes. Mark 0.00 out of Question 15 Incorrect 5.00 Flag question Your answer is incorrect. The correct answer is: The [need-to-know] principle, is useful in limiting the amount of damage a faulty process can cause in the system. Mark 2.50 out of Question 16 Partially correct 5.00 Flag question Your answer is partially correct. You have correctly selected 2. The correct answer is: The association between a [process] and a [domain]may be either [static ] or [dynamic]. Mark 5.00 out of Question 17 Correct 5.00 Flag question Your answer is correct. The correct answer is: In the [MULTICS] system, the protection domains are organized hierarchically into a [ring structure]. Mark 5.00 out of Question 18 Correct 5.00 Flag question The least-privilged principle,isusefulinlimitingtheamountofdamageafaultyprocesscancauseinthesystem. Theassociationbetweena process anda domain maybeeither dynamic or static . Inthe MULTICS system,theprotectiondomainsareorganizedhierarchicallyintoa ringstructure . Which of the following statements is not TRUE about Compiler Based Enforcement? Select one: Protection requirements can be defined independently of any particular operating system facilities. Protection needs are declared, rather than programmed. The means for enforcement need to be provided by the designer of a subsystem. Protection is embedded in linguistic concept of data type. Your answer is correct. The correct answer is: The means for enforcement need to be provided by the designer of a subsystem. Mark 5.00 out of Question 19 Correct 5.00 Flag question Stack inspection is : Select one: Your answer is correct. The correct answer is: All the options are correct Mark 8.24 out of Question 20 Partially correct 10.00 Flag question Useful for inspecting classes from un trusted sources Protection mechanism provided in Java programming language All the options are correct Providing methods to request access to a protected resource either directly or indirectly Consider the following file-access-control situations. For each, choose whether it could be encoded using the standard UNIX owner/group/other permissions model - and if so, choose appropriate users, groups and permissions If you do not think the permissions can be written in owner/group/other format, choose 'No' then pick the 'It cannot be done' option for the other answers to that question. a) Harry creates a file. He wants to give read/write access to Ron and Hermione, and no access to anyone else. Can this be done using the owner/group/other model? Yes If so: Who would be the owner of the file? Harry Who would be in the group for the file? Ron: Yes Hermione: Yes What would their permissions be? rw- What would the 'other' permissions be? --- b) Voldemort creates a file. He wants to give Snape read/write access, Bellatrix read-only access, and no access to anyone else. Can this be done using the owner/group/other model? No If so: Who would be the owner of the file? Voldemort Who would be in the group for the file? Snape: No/itcannotbedone Bellatrix: No/itcannotbedone What would their permissions be? rw- What would the 'other' permissions be? rw- c) Filch creates a file. He wants to give staff read/write access, and other users (e.g. pupils) read-only access. Can this be done using the owner/group/other model? Yes If so: Who would be the owner of the file? Filch Who would be the group for the file? Staff Week 9 Quiz - Extended Deadline 10:00, March the 30th for students who have been in isolation due to corona virus. Mark 10.00 out of Question 1 Correct 10.00 Your answer is correct. The correct answer is: RC4 Mark 7.20 out of Question 2 Partially correct 8.00 Flag question ----------- isasymmetricstreamcipher Select one: None of the three options AES DES RC4 Flag question boot A file A macro An encrypted Tunneling virusinfectsthe boot sectorofthesystem viruschangesthestartoftheprogramsothatexecutionjumpstoits code . is written in low level programming languages. virusincludes decryption codealongwiththeencryptedvirus. virus attempts to bypass detection by an antivirus by installing itself in the interrupt handler chain Your answer is partially correct. You have correctly selected 9. The correct answer is: [boot] virus infects the [boot] sector of the system A [file] virus changes the start of the program so that execution jumps to its [code]. A [macro] is written in [high] level programming languages. An [encrypted] virus includes [decryption]code along with the encrypted virus. [Tunneling ] virus attempts to bypass detection by an antivirus by installing itself in the [interrupt handler ] chain Mark 10.00 out of Question 3 Correct 10.00 Flag question What would their permissions be? What would the 'other' permissions be? r-- rw- A worm Select one: use the spawn mechanism to ravage system performance All the three options Your answer is correct. The correct answer is: All the three options Mark 10.00 out of Question 4 Correct 10.00 Flag question Your answer is correct. The correct answer is: A [worm]is structured as a complete, standalone program whereas a [virus] is a fragment of code embedded in a legitimate program. Mark 8.00 out of Question 5 Correct 8.00 Flag question Your answer is correct. The correct answer is: Users with privileged system rights have constrained internet and email access from their privileged account A worm is structured as a complete, standalone program whereas a virus is a fragment of code embedded in a legitimate program. Limit privileged user functionality means: Select one: None of the three options Administrators have full internet and email access from their privileged account Users with privileged system rights have constrained internet and email access from their privileged account Users with ‘normal’ privileges should be prevented from installing or disabling any software or services running on the system. Mark 8.00 out of Question 6 Correct 8.00 Your answer is correct. The correct answer is: D-denial of service Mark 10.00 out of Question 7 Correct 10.00 Flag question Which of the following attacks is not type of social engineering attacks ? Select one: D-denial of service Baiting Phishing Pretexting Flag question A code segment that misuses its environment is called Select one: a worm a back door a trap door a Trojan horse can shut down an entire network continue to grow as the Internet expands Your answer is correct. The correct answer is: a Trojan horse Mark 10.00 out of Question 8 Correct 10.00 Flag question Your answer is correct. The correct answer is: the computer supplies one part of a password and the user enters the other part Mark 8.00 out of Question 9 Correct 8.00 Flag question Your answer is correct. The correct answer is: The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. Mark 6.67 out of Question 10 Partially correct 10.00 Flag question Your answer is partially correct. You have correctly selected 2. The correct answer is: Modern [Cryptography] is based on [secrets] called [keys]that are selectively distributed to computers in a network and used to process messages. Mark 8.00 out of Question 11 Correct 8.00 Flag question In a paired-password system, Select one: two users must enter their own separate password to gain access to the system passwords must contain equal amounts of numbers and digits paired together the computer supplies one part of a password and the user enters the other part the user specifies two passwords The concept "system reliability" means: Select one: None of the three options The Probability of a system that will be functioning without errors during daytime The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. The Probability of a system that will be functioning correctly at any given time Modern Cryptography is based on tokens called keys that are selectively distributed to computers in a network and used to process messages. The backdoor program is Select one: Used in distributed attacks that focus on the malicious modification to software/hardware at the factory time. Used to gain unauthorized access to information All the three options Used in distributed attacks that focus on the malicious modification to software/hardware at the distribution time Your answer is correct. The correct answer is: All the three options Week 10 Coursework - Deadline is extended to 10:00, 3'rd of April Mark 10.00 out of Question 1 Correct 10.00 Flag question Fill in the missing words: In Linux, a Shell is a command interpreter that allows users to type commands from the keyboard to interact with the operating system kernel . It is a computer program that interprets the commands the user types and sends them totheoperatingsystem.Furthermore,itprovidesa programming environmentconsistingofenvironment variables . Your answer is correct. The correct answer is: Fill in the missing words: It is a computer program that [interprets ] the commands the user types and sends them to the operating system. Furthermore, it provides a [programming ] In Linux, a [Shell] is a command [interpreter ] that allows users to type commands from the keyboard to interact with the operating system [kernel]. environment consisting of environment [variables ]. Mark 0.00 out of Question 2 Incorrect 10.00 Flag question Which of the following statements is TRUE about Linux schedular? Select one: Processes are assigned priorities that are based on the nice value only. Processes with shorter sleep times are often CPU-bound and thus will have higher priorities. All of the options The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. Your answer is incorrect. The correct answer is: The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. Mark 0.00 out of Question 3 Incorrect 10.00 Flag question Your answer is incorrect. The correct answer is: Linux uses the same internal representation for processes and threads Which of the following statements is TRUE about Linux Threads? Select one: All of the three options Linux uses the same internal representation for processes and threads A thread is a new process that has its own address space Fork creates a new process with its own identity, but that is allowed to share the data structures of its parent Mark 10.00 out of Question 4 Correct 10.00 Flag question Your answer is correct. The correct answer is: UNIX process management separates the creation of [processes] and the running of a new program into two distinct operations. [fork] system call [creates ] a new process and a new program is run after a system call to [execve] . UNIXprocessmanagementseparatesthecreationof processes andtherunningofanewprogramintotwodistinctoperations. fork systemcall creates anewprocessandanewprogramisrunafterasystemcallto execve . Mark 10.00 out of Question 5 Correct 10.00 Flag question Which of the following statements is TRUE about The Linux source code is freely and widely available over the Internet and from CD-ROM vendors? Select one: Linux’s source code is open to scrutiny by both the good guys and the bad guys. Open source code implies both that security weaknesses can be found and fixed faster by the Linux community, increasing the security of the system; and that attackers can more easily find any weaknesses that do remain in Linux. All of the options Attackers’ jobs are made easier if they have access to the source code of the system they are trying to penetrate Your answer is correct. The correct answer is: All of the options Mark 10.00 out of Question 6 Correct 10.00 Flag question Which of the following sentences is TRUE about writing an operating system using high-level programming languages ? Select one: All of the options High-level programming languages have powerful programming environments that include tools such as debuggers and performance profilers that could be handy for developing code. The number of programming errors is reduced as the code becomes more compact High-level languages may provide advanced features such as bounds checking that further minimize programming errors and security loopholes. Your answer is correct. The correct answer is: All of the options Mark 10.00 out of Question 7 Correct 10.00 Flag question Which of the following statements is TRUE about Linux virtual manager? Select one: The VM manager maintains logical and physical views of a process’s address space All of the options Your answer is correct. The correct answer is: All of the options Mark 10.00 out of Question 8 Correct 10.00 Flag question Which of the following is TRUE about keeping functionality in shared libraries rather than in the kernel itself? Select one: Performance All of the options Manageability Reliability Your answer is correct. The correct answer is: All of the options Mark 10.00 out of Question 9 Correct 10.00 Flag question The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with full access to the all the physical resources of the computer.Itscodeanddatastructuresarekeptinthe same single addressspace. Your answer is correct. The correct answer is: The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with [full] access to the [all] the [physical ] resources of the computer. Its code and data structures are kept in the [same] [single ] address space. Mark 10.00 out of Question 10 Correct 10.00 Flag question Your answer is correct. The correct answer is: Select the Missing words: In Linux, [threads] are implemented within the [kernel] by a [clone] mechanism that creates a new process within the same virtual address space as the Select the Missing words: In Linux, threads are implemented within the kernel by a clone mechanism that creates a new process withinthesamevirtualaddressspaceasthe parent process. The VM manager creates a new virtual address space when there is a fork system call The VM manager creates a new virtual address space when there is a exec system call [parent ] process. Quiz -1 Assessed Coursework, Deadline 10:00am Tuesday 28/01/2020 Question 1 Correct Mark 10.00 out of 10.00 Flag question Select whether each of the following statements is true or false: A process can move directly from a new to a running state An interrupt causes a process to go from a running to a ready state A stack overow can occur because too many objects are created in a program using new Function parameters are stored in the stack of a process Many processes may run the same program True False True True False The correct answer is: Select whether each of the following statements is true or false: A process can move directly from a new to a running state [False] An interrupt causes a process to go from a running to a ready state [True] A stack overow can occur because too many objects are created in a program using new [False] Function parameters are stored in the stack of a process [True] Many processes may run the same program [True] Question 2 Incorrect Mark 0.00 out of 10.00 Flag question Schedule the following processes using rst come rst served scheduling: P0 duration: 6 arrives: 0 priority: 0 P1 duration: 1 arrives: 5 priority: 5 P2 duration: 9 arrives: 2 priority: 2 P3 duration: 5 arrives: 6 priority: 6 P4 duration: 9 arrives: 1 priority: 1 What is the total turnaround time? Answer: When using migration in multiprocessing a process regularly checks processor loads and redistributes processes. Scheduling is most ecient when . P1 (duration 19) P2 (duration 15) P3 (duration 2) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order . Running more than one process at once on a system is called . 66 Hint: each process runs until it nishes, processes start in the order they arrived, see the lecture notes for more details The correct answer is: 86 Question 3 Partially correct Mark 8.33 out of 10.00 Flag question Almost there... You have correctly selected 5. The correct answer is: When using [push] migration in multiprocessing a process regularly checks processor loads and redistributes processes. Scheduling is most ecient when [there is a mixture I/O and CPU bound processes]. P1 (duration 19) P2 (duration 15) P3 (duration 2) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order [P3] [P2] [P1]. Running more than one process at once on a system is called [Multiprogramming]. Question 4 Correct Mark 15.00 out of 15.00 Flag question Schedule the following processes using pre-emptive priority scheduling: P0 duration: 7 arrives: 11 priority: 19 P1 duration: 14 arrives: 8 priority: 2 P2 duration: 13 arrives: 12 priority: 15 P3 duration: 5 arrives: 10 priority: 18 P4 duration: 9 arrives: 0 priority: 5 Fill in the schedule below: Process Start Time Runs For P4 0 8 P1 8 14 P4 22 1 P2 23 13 P3 36 5 P0 41 7 Now complete the waiting and turnaround times for each process, then the total and averages. Process Waiting Time Turnaround Time P0 P1 30 37 0 14 P2 11 24 P3 P4 Total Average 26 31 14 23 81 129 16.2 25.8 The correct schedule is: 0: P4 (8) 8: P1 (14) 22: P4 (1) 23: P2 (13) 36: P3 (5) 41: P0 (7) Waiting times: P0 30 P1 0 P2 11 P3 26 P4 14 Turnaround times : P3 31 P4 23 P1 14 P2 24 P0 37 Question 5 Correct Mark 15.00 out of 15.00 Flag question This question is about multi-queue scheduling. Select all the true statements from the list below: Select one or more: In multi-queue scheduling all queues must have the same scheduling algorithm. Multi-level feedback queues can be used for priority scheduling. Correct! Multi-queue scheduling can be used on single processor systems. Correct! Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling Another option is for higher priority queues to have absolute priority, using aging to prevent starvation. In Multi-level feedback queue scheduling jobs always stay on the same queue. Correct! Correct! Well done. The correct answers are: Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling, Multi-queue scheduling can be used on single processor systems., Multi-level feedback queues can be used for priority scheduling. Information Flag question Information for answering Round Robin Scheduling Questions. If you have a quantum of 3 for example, and a schedule like this: 0: P0 (3) 3: P0 (3) 6: P1 (3) 9: P2 (3) 12: P2 (1) Then don't enter it as above, with the original quanta, but rather include the total time each process is running, so: 0: P0 (6) 6: P1 (3) 9: P2 (4) In your question there wouldn't be enough boxes to do it the rst way round. Question 6 Partially correct Mark 9.00 out of 15.00 Flag question Schedule the following processes using round robin scheduling with quantum 3: P0 duration: 7 arrives: 8 P1 duration: 14 arrives: 7 P2 duration: 3 arrives: 5 P3 duration: 11 arrives: 14 P4 duration: 14 arrives: 0 Fill in the schedule below: Process Start Time Runs For P4 P2 0 6 6 3 P1 P0 9 3 12 3 P3 P4 15 3 18 3 P1 P0 21 3 24 3 P3 27 3 P4 30 3 P1 33 3 P0 36 1 P3 37 3 P4 40 2 P1 42 3 P3 45 2 P1 47 2 Now complete the waiting and turnaround times for each process, then the total and averages. Process P0 P1 P2 P3 P4 Total Average Waiting Time Turnaround Time 22 29 28 1 42 4 22 33 28 42 101 150 20.1 30 The correct schedule is: 0: P4 (6) 6: P2 (3) 9: P4 (3) 12: P1 (3) 15: P0 (3) 18: P4 (3) 21: P3 (3) 24: P1 (3) 27: P0 (3) 30: P4 (2) 32: P3 (3) 35: P1 (3) 38: P0 (1) 39: P3 (3) 42: P1 (3) 45: P3 (2) 47: P1 (2) Waiting times: P0 24 P1 28 P2 1 P3 22 P4 18 Turnaround times : P4 32 P1 42 P2 4 P3 33 P0 31 Question 7 Correct Mark 10.00 out of 10.00 Flag question Select whether each of the following statements is true or false: Without context switching it is not possible to listen to music and do word processing simultaneously on a single processor, single core, machine . In multi-level queue scheduling one queue always has absolute priority over other queues . The Linux 2.5 scheduler avoids starvation by ensuring processes cannot run for longer than their quantum until all others have also been allowed their quantum . A child process always shares the resources of its parent . True False True False Congratulations! The correct answer is: Select whether each of the following statements is true or false: Without context switching it is not possible to listen to music and do word processing simultaneously on a single processor, single core, machine [True]. In multi-level queue scheduling one queue always has absolute priority over other queues [False]. The Linux 2.5 scheduler avoids starvation by ensuring processes cannot run for longer than their quantum until all others have also been allowed their quantum [True]. A child process always shares the resources of its parent [False]. Question 8 Partially correct Mark 12.43 out of 15.00 Flag question Schedule the following processes using shortest remaining time rst scheduling: P0 duration: 7 arrives: 19 P1 duration: 22 arrives: 0 P2 duration: 13 arrives: 3 P3 duration: 15 arrives: 22 P4 duration: 20 arrives: 15 Fill in the schedule below: Process Start Time Runs For P1 P2 0 3 3 13 P1 16 3 P0 19 7 P3 26 15 P1 41 16 P4 57 20 Now complete the waiting and turnaround times for each process, then the total and averages. Process P0 P1 P2 P3 P4 Total Waiting Time Turnaround Time 0 7 35 0 57 13 4 19 37 57 76 153 Average 15.2 30.6 The correct schedule is: 0: P1 (3) 3: P2 (13) 16: P1 (3) 19: P0 (7) 26: P3 (15) 41: P1 (16) 57: P4 (20) Waiting times: P0 0 P1 35 P2 0 P3 4 P4 42 Turnaround times : P0 7 P1 57 P4 62 P2 13 P3 19 Week 2 Quiz - Assessed Coursework, Deadline 10:00am 04/02/2020 Select whether each of the following statements is true or false: If a thread calls sleep() it moves from a running to a runnable state . Java automatically creates a separate thread for a GUI to make sure it remains responsive . The only way to create a class that will run as a thread in Java is to extend Thread . A line of Java code is executed on a CPU as a single atomic instruction . Question 1 Correct Mark 10.00 out of 10.00 Flag question False True False False Congratulations! The correct answer is: Select whether each of the following statements is true or false: If a thread calls sleep() it moves from a running to a runnable state [False]. Java automatically creates a separate thread for a GUI to make sure it remains responsive [True]. The only way to create a class that will run as a thread in Java is to extend Thread [False]. A line of Java code is executed on a CPU as a single atomic instruction [False]. Question 2 Correct Mark 20.00 out of 20.00 Flag question A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread r = new Printer("R"); r.start(); Thread q = new Printer("Q"); q.start(); try{ r.join(); } catch (Exception e){ e.printStackTrace(); } for(int i = 0; i < 10; ++i){ System.out.print(“P”); } } } The code for the class Printer is correctly implemented, the class extends Thread and the run method prints out the letter given as an argument to the constructor 10 times (it may, or may not, do other computation that does not produce any output). Which of the following are possible outputs of this program? (to save laborious counting you can safely assume that all answers contain 10Ps, 10Qs and 10Rs). 0: QQQRRRQQRRQRRQQRQRQPRPPPPPPPPP 1: PPPPPPPPPPRRRRRRRRRRQQQQQQQQQQ 2: QQQQQQQQQQPPPPPPPPPPRRRRRRRRRR 3: RPRPRPRPRPRPRPRPRPRPQQQQQQQQQQ 4: QQQRRRQQRRQRRQQRQRRPPQPPPPPPPP 5: QRQRQRQRQRQRQRQRQRQRPPPPPPPPPP 6: QRPQRPQRPQRPQRPQRPQRPQRPQRPQRP 7: QPQPQPQPQPQPQPQPQPQPRRRRRRRRRR 8: RRRRRRRRRRPPPPPPPPPPQQQQQQQQQQ 9: QQQQQQQQQQRRRRRRRRRRPPPPPPPPPP Select one: 9 and 5 only 9, 8, 5, 0 and 4 only 9, 2 and 7 only 9, 2, 5 and 0 only 9 only All of the above 9, 8, 5 and 4 only None of the above. Correct! Since r.join() is called the main thread must wait for r to nish before continuing. The correct answer is: 9, 8, 5 and 4 only Question 3 Correct Mark 10.00 out of 10.00 Flag question Select whether each of the following statements is true or false: There is often value in writing threaded code for a machine with only 1 CPU. In a threaded program one thread must nish executing before another can start. All programs should be multi-threaded. . Atomic instructions can be split into a number of smaller instructions. . . . True False False False Congratulations! The correct answer is: Question 4 Correct Mark 15.00 out of 15.00 Flag question In the following solution to the critical section problem (note that the two processes are slightly dierent): boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to . . starvation of q violation of mutual exclusion This program satises the requirement for . It is that p can never starve. Freedom From Deadlock True The correct answer is: In the following solution to the critical section problem (note that the two processes are slightly dierent): boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to [violation of mutual exclusion]. Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to [starvation of q]. This program satises the requirement for [Freedom From Deadlock]. It is [True] that p can never starve. Question 5 Correct Mark 10.00 out of 10.00 Flag question To verify that a solution to the critical section problem is correct we must show that the condition. To verify that a solution to the critical section problem is incorrect we must show that the condition. If no process is able to enter its critical section this is called Select whether each of the following statements is true or false: There is often value in writing threaded code for a machine with only 1 CPU. [True]. In a threaded program one thread must nish executing before another can start. [False]. All programs should be multi-threaded. [False]. Atomic instructions can be split into a number of smaller instructions. [False]. . Correct, well done! The correct answer is: To verify that a solution to the critical section problem is correct we must show that [all interleavings satisfy] the condition. To verify that a solution to the critical section problem is incorrect we must show that [at least one interleaving breaks] the condition. If no process is able to enter its critical section this is called [deadlock]. Question 6 Correct Mark 20.00 out of 20.00 Flag question Consider the following solution to the critical section problem: boolean wantp <- false, wantq <- false p q loop_forever p1: non-critical section p2: wantp <- true P3: while wantq p4: wantp <- false P5: wantp <- true p6: critical section p7: wantp <- false loop_forever q1: non-critical section q2: wantq <- true q3: while wantp q4: wantq <- false q5: wantq <- true q6: critical section q7: wantq <- false Which of the three properties does this solution satisfy? Select one: All Three: Mutual Exclusion, Freedom From Starvation, Freedom From Deadlock. Mutual Exclusion Only. Freedom From Starvation Only. Freedom From Deadlock Only. None. Mutual Exclusion and Freedom From Deadlock only. starvation. Correct! Make sure you can give the scenario that leads to Freedom From Deadlock and Freedom From Starvation only. Mutual Exclusion and Freedom From Starvation only. A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread p = new Printer("p"); The correct answer is: Mutual Exclusion and Freedom From Deadlock only. Question 7 Correct Mark 15.00 out of 15.00 Flag question Thread q = new Printer("Q"); p.run(); q.run(); for(int i = 0; i < 10; ++i){ System.out.println("R"); } } } What is the maximum number of threads belonging to this program running at any one time during its execution? Select one: 0 1 Correct! Although the programmer tried to start to threads they called run() instead of start(). This error meant that no new threads were created. Further exercise: if the programmer had called start() how many processes would be running? 2 3 Week 3 Quiz - Assessed Coursework, Deadline 10:00 am 11/02/2020 Select whether each of the following statements is true or false: Starvation can occur in the bakery algorithm if a process exits in its non-critical section. . The bakery algorithm would still work if we favour higher numbered threads when breaking ties, rather than lower numbered threads. . If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twice whilst p has to wait. . The bakery algorithm is ecient for use in practice. . The correct answer is: 1 Question 1 Partially correct Mark 7.50 out of 10.00 Flag question False False False False You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: Starvation can occur in the bakery algorithm if a process exits in its non-critical section. [False]. The bakery algorithm would still work if we favour higher numbered threads when breaking ties, rather than lower numbered threads. [True]. If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twice whilst p has to wait. [False]. The bakery algorithm is ecient for use in practice. [False]. Question 2 Correct Mark 10.00 out of 10.00 Flag question Which of the following are valid outputs for the following program: Semaphore S1<- 0, S2 <- 0 p q r p1: print(“p”) p2: signal(S1) p3: signal(S2) q1: wait(S1) q2: print(“q”) r1: wait(S2) r2: print(“r”) Select one or more: rpq prq Good, that was the hard one, the scheduler might permit p1,p2,p3 and then schedule r. qpr qrp pqr Correct! And there's at least one more. rqp Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. The correct answers are: pqr, prq Question 3 Correct Mark 20.00 out of 20.00 Flag question Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section Solution 1: Solution 2: Solution 3: Solution 4: Both Both FreedomFrom Deadlock Only Mutual Exclusion Only Solution 5: FreedomFrom Deadlock Only Solution 6: Solution 7: Solution 8: Both FreedomFrom Deadlock Only Mutual Exclusion Only The correct answer is: Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section Solution 1: [Both] Solution 2: [Both] Solution 3: [FreedomFrom Deadlock Only] Solution 4: [Mutual Exclusion Only] Solution 5: [FreedomFrom Deadlock Only] Solution 6: [Both] Solution 7: [FreedomFrom Deadlock Only] Solution 8: [Mutual Exclusion Only] Question 4 Correct Mark 20.00 out of 20.00 Flag question Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends safeToCross = private String name; public Pedestrian(String nameIn){ name = nameIn; { Thread static Semaphore public void run() { new Semaphore(2) ; } for(int i = 0; i < 3; ++i){ try{ safeToCross.acquire(); System.out.println("Pedestrian " + name + " Entering the Bridge"); System.out.println("Pedestrian " + name + " Leaving the Bridge"); } catch ( e){ e.printStackTrace(); } Thread.sleep(100); safeToCross.release(); } } public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave. ; Pedestrian pete = new Pedestrian("Pete"); pete. ; Pedestrian jackie = new Pedestrian("Jackie"); jackie. ; Pedestrian jane = new Pedestrian("Jane"); jane. ; } } start() InterruptedException start() start() start() Your answer is correct. Question 5 Partially correct Mark 7.50 out of 10.00 Flag question Select whether each of the following statements is true or false: Test and set is provided by software. . Semaphores are software and are usually provided by the operating system kernel . False True The correct answer is: Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends [Thread] { [static Semaphore] safeToCross = [new Semaphore(2)]; private String name; public Pedestrian(String nameIn){ name = nameIn; } [public void run()]{ for(int i = 0; i < 3; ++i){ try{ [safeToCross.acquire();] System.out.println("Pedestrian " + name + " Entering the Bridge"); [Thread.sleep(100);] System.out.println("Pedestrian " + name + " Leaving the Bridge"); [safeToCross.release();] } catch ([InterruptedException] e){ e.printStackTrace(); } } } public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave.[start()]; Pedestrian pete = new Pedestrian("Pete"); pete.[start()]; Pedestrian jackie = new Pedestrian("Jackie"); jackie.[start()]; Pedestrian jane = new Pedestrian("Jane"); jane.[start()]; } } Atomic swap can be used to solve the critical section problem without any other mechanisms. . If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. . False True You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: Test and set is provided by software. [False]. Semaphores are software and are usually provided by the operating system kernel [True]. Atomic swap can be used to solve the critical section problem without any other mechanisms. [True]. If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. [True]. Question 6 Correct Mark 5.00 out of 5.00 Flag question Which of the three types of semaphore can be used to implement a solution to the critical section problem without the risk of starvation? Select one: None of them. Busy Wait Semaphores and Blocked Set Semaphores. All of them. Busy Wait Semaphores and Blocked Queue Semaphores. Busy Wait sempahores only. Blocked Queue semaphores only. Correct! Blocked Queue and Blocked Set semaphores only. Blocked Set semaphores only. A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain species that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the oor). Complete the following pseudocode model of the problem: The correct answer is: Blocked Queue semaphores only. Question 7 Partially correct Mark 12.00 out of 15.00 Flag question Semaphore CrateOnTrain <- , Semaphore spaceOnTrain <- 0 10 Loading Crane Unoading Crane loop forever: pickup crate from oor wait(spaceOnTrain) load crate onto train signal(crateOnTrain) loop forever: wait(crateOnTrain) unload crate from train signal(spaceOnTrain) put down crate on oor The correct answer is: A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain species that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the oor). Complete the following pseudocode model of the problem: Semaphore CrateOnTrain <- [10], Semaphore spaceOnTrain <- [0] Loading Crane Unoading Crane loop forever: [pickup crate from oor] [wait(spaceOnTrain)] [load crate onto train] [signal(crateOnTrain)] loop forever: [wait(crateOnTrain)] [unload crate from train] [signal(spaceOnTrain)] [put down crate on oor] Question 8 Correct Mark 10.00 out of 10.00 Flag question Consider the following solution to the dining philosophers problem in which ve philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to . deadlock Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock . Changing the order in which philosopher t picks up the forks will prevent deadlock . Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock . false true true The correct answer is: Consider the following solution to the dining philosophers problem in which ve philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to [deadlock]. Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock [false]. Changing the order in which philosopher t picks up the forks will prevent deadlock [true]. Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock [true]. Week 4 Quiz - Assessed Coursework, Deadline 18/02/2020 @ 10am Consider the follow diagram representing the states of threads in Java when using monitors. Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) (c) Question 1 Correct Mark 10.00 out of 10.00 Flag question Runnable Running (1) start() (2) (3) (4) (5) (6) The scheduler can cause transitions on edges . run() yield() wait() notifyAll() run() ends 2 and 3 The correct answer is: Consider the follow diagram representing the states of threads in Java when using monitors. Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) [Runnable] (c) [Running] (1) [start()] (2) [run()] (3) [yield()] (4) [wait()] (5) [notifyAll()] (6) [run() ends] The scheduler can cause transitions on edges [2 and 3]. Question 2 Correct Mark 20.00 out of 20.00 Flag question A programmer creates the following two Java classes: public class A { public synchronized void a1(){ //do something } public void a2(){ //do something } public synchronized int a3(){ int var = 0; //do something changing var return var; } } public class B { public void b1(){ //do something } public synchronized int b2(){ int var = 0; //do something changing var return var; } public void b3(){ //do something } } Then a main method which does the following: public static void main(String[] args){ A firstA = new A(); A secondA = new A(); B firstB = newB(); //create some threads that perform operations on firstA, secondA and first B and start them } The precise details of the creation and function of the threads are not important, so they are not given, you may assume that they run in parallel and call methods on the created objects. Further you may assume that no other mechanisms that are not shown prevent methods from running concurrently. Which of the following groups of methods cannot be run concurrently (i.e. will be sequenced so that one nishes before the other starts) if called at the same time by two dierent threads? Select one or more: rstA.a2() and rstB.b2() rstA.a2() and secondA.a2() rstA.a2() and rstA.a2() rstB.b2() and rstB.b2() Synchronized methods in the same object cannot be run in parallel, and that includes with themselves, the keyword synchronized requires one to complete before the other starts. Two dierent threads can attempt to call the same method at once, think for example, of two producers calling produce at the same time rstB.b2() and rstB.b3() rstA.a2() and rstB.b1() rstA.a1() and secondA.a3() rstA.a2() and secondA.a3() rstB.b1() and rstB.b3() secondA.a1() and rstB.b2() secondA.a1() and secondA.a3() synchronized requires one to complete before the other starts Synchronized methods in the same object cannot be run in parallel, the keyword The correct answers are: secondA.a1() and secondA.a3(), rstB.b2() and rstB.b2() Question 3 Correct Mark 10.00 out of 10.00 Flag question Select whether each of the following statements is true or false: Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource . It is sometimes more ecient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run . In classical monitors all methods are subject to mutual exclusion . Java monitors use priority Entering = Waiting > Notifying .
True
True
True
Congratulations!
The correct answer is:
Select whether each of the following statements is true or false:
Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource [True].
It is sometimes more ecient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run [True].
In classical monitors all methods are subject to mutual exclusion [True]. Java monitors use priority Entering = Waiting > Notifying [False].
Question 4 Correct Mark 10.00 out of 10.00 Flag question
False
This question is about Java programming using swing. Select whether each of the following statements is true or false:
Swing automatically creates threads to make GUIs more responsive .
All event handlers run in their own separate thread. .
Concurrency bugs can only ever occur when the programmer exlicitly creates a thread. . Threading problems cannot occur when using swing because it is thread safe. .
True
False
False
False
Congratulations!
The correct answer is:
This question is about Java programming using swing. Select whether each of the following statements is true or false:
Swing automatically creates threads to make GUIs more responsive [True].
All event handlers run in their own separate thread. [False].
Concurrency bugs can only ever occur when the programmer exlicitly creates a thread. [False]. Threading problems cannot occur when using swing because it is thread safe. [False].
Question 5 Partially correct Mark 9.29 out of 10.00 Flag question
Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the

crossing together.
1: public class CrossingUser
extends Thread {
2: private String mode;
3: private Crossing
crossing;
4:
5: public
CrossingUser(Crossing toUse,
String modeIn){
6: mode = modeIn;
7: crossing = toUse;
8: }
9:
10: public void run(){
11:
crossing.enterCrossing(this);
12:
crossing.useCrossing(this);
13:
crossing.leaveCrossing(this);
14: }
15:
16: public int timeToCross(){
17:
if(mode.equals(“ROAD”)){
return 50;
} else {
return 200; }
return mode;
18:
19:
20:
21:
22:
23:
24:
{
25:
26: }
27: }
}
public String getMode()
1: public class Crossing {
2:
3: private String mode = “”;
4: private int users = 0;
5:
6:
enterCrossing(CrossingUser u){ 7: (
public synchronized void
while
!mode.equals(“”)
||
!u.getMode().equals(mode)
){
9: ;
8: try{
wait()
10:
e){
11:
13:
13:
14:
15:
16:
Entering the Crossing”);
17: }
18:
19:
useCrossing(CrossingUser u){
InterruptedException
}
} catch (
e.printStackTrace();
}
mode = u.getMode()
;
++users;
System.out.println(u.getMode() + ” User
public void
20: 21:
22:
23:
24:
25: }
26:
27:
try{
} catch ( e){
e.printStackTrace();
}
Thread.sleep(u.timeToCross())
;
InterruptedException
public synchronized void
leaveCrossing(CrossingUser u){
28:
29: –users;
30: if(users == 0){
31: ;
mode = “”
32: }
33: System.out.println(u.getMode() + ” User
Leaving the Crossing”);
34: ;
35: } 36: }
notifyAll()
Your answer is partially correct.
You have correctly selected 13. The correct answer is:

Question 6 Partially correct Mark 9.17 out of 10.00 Flag question
Now the following rules are to be enforced:
It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2);
No more than 1 road user can be on the crossing at the same time (restriction 3).
Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You’re answer will not be marked as correct unless you complete the restrictions in the specied order (this is a limitiation of KEATS, of course any order of the conditions would work in Java).
Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together.
1: public class CrossingUser
extends Thread {
2: private String mode;
3: private Crossing crossing;
4:
5: public
CrossingUser(Crossing toUse, String
modeIn){
6: mode = modeIn;
7: crossing = toUse;
8: }
9:
10: public void run(){
11:
crossing.enterCrossing(this);
12:
crossing.useCrossing(this);
13:
crossing.leaveCrossing(this);
14: }
15:
16: public int timeToCross(){
17:
18:
19:
20:
21:
22:
23:
24:
25:
26: }
27: }
if(mode.equals(“ROAD”)){
return 50;
} else {
return 200; }
}
public String getMode(){
return mode;
1: public class Crossing {
2:
3: private String mode = “”;
4: private int users = 0;
5:
6: [public synchronized void]
enterCrossing(CrossingUser u){
7: [while]([!mode.equals(“”) ] [&&]
[!u.getMode().equals(mode)]){
8:
9:
10:
{
11:
13:
13:
try{
[wait()];
} catch ([InterruptedException] e)
e.printStackTrace();
}
}
[mode = u.getMode()];
++users;
System.out.println(u.getMode() + ” User
14:
15:
16:
Entering the Crossing”);
17: }
18:
19:
20:
21:
22:
23:
24:
25: }
26:
[public void] useCrossing(CrossingUser u){
try{
[Thread.sleep(u.timeToCross())];
} catch ([InterruptedException] e){
e.printStackTrace();
}
27: [public synchronized void]
leaveCrossing(CrossingUser u){
28:
29: –users;
30: if(users == 0){
31: [mode = “”];
32: }
33: System.out.println(u.getMode() + ”
User Leaving the Crossing”);
34: [notifyAll()];
35: }
36: }

while
//restriction 3
try {//etc.
}
!u.getMode().equals(mode)
||
(( ) //restriction 1
!mode.equals(“”)
||
users > 2
&&
() //restriction 2
( )){
u.getMode().equals(“FOOT”)
||
users > 0
&&
u.getMode().equals(“ROAD”)
Your answer is partially correct.
You have correctly selected 11. The correct answer is:
Now the following rules are to be enforced:
It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2);
No more than 1 road user can be on the crossing at the same time (restriction 3).
Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You’re answer will not be marked as correct unless you complete the restrictions in the specied order (this is a limitiation of KEATS, of course any order of the conditions would work in Java).
[while](([!u.getMode().equals(mode)] [&&] [!mode.equals(“”) ] ) [||] //restriction 1
([users > 2] [&&] [u.getMode().equals(“FOOT”)]) [||] //restriction 2
([users > 0] [&&] [u.getMode().equals(“ROAD”)])){ //restriction 3
try {//etc. }
Question 7 Partially correct Mark 11.25 out of 15.00 Flag question
Consider the following method (and class variables), that are intended to enforce the following rules:
The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once;
Only one car can travel westbound at once.
int carCount = 0;
boolean westbound = false;
public synchronized void enterBridge(Vehicle v){
//block
westbound = v.getWestbound(); //set direction to your direction
++carCount; //increment cars using bridge
System.out.println(v + “ entering the bridge”);
}
Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of the code is correctly implemented.

block 1:
while((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 2:
while((v.getWestbound() != westbound && carCount > 0) &&
(!v.getWestbound() && carCount > 2) &&
(v.getWestbound() && carCount > 0)) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 3:
if((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 4:
if((v.getWestbound() != westbound && carCount > 0)) {
if (!v.getWestbound() && carCount > 2) {
if (v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
} }
}
block 5:
if((v.getWestbound() != westbound && carCount > 0)) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(!v.getWestbound() && carCount > 2) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}

}
block 6:
while((v.getWestbound() != westbound && carCount > 0)) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
while(!v.getWestbound() && carCount > 2) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
while(v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
Select one or more:
a. block 1 Correct!
b. block 2
c. block 3 Using if instead of while means that the condition will not be rechecked when a thread is awoken, thus if two waiting vehicles wake up following notify all, both will proceed without having to recheck the condition. Using while ensures that the condition must be rechecked before the loop can be exited, thus one will wait again.
d. block 4 e. block 5 f. block 6
Consider the following methods to exit and cross the bridge that are to be a part of the same class as the previous enterBridge method.
public synchronized void exitBridge(Vehicle v){
–carCount;
System.out.println(v + “ exiting the bridge”);
notifyAll();
}
public void crossBridge(){
try{
Thread.sleep(100);
} catch (InterruptedException e){
e.printStackTrace();
}
}
The correct answer is: block 1
Question 8 Correct Mark 15.00 out of 15.00 Flag question
Select all statements that are correct:

Select one or more:
Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock. Correct! No cars would be able to enter the bridge once three had entered because they would wait indentely for car count to be low enough.
If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should. Correct! The threads would each have to wait in turn to execute crossBridge, and could therefore not be sleeping at the same time.
Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one. Correct!
If the order of the println and notifyAll statements are swapped it is possible that another car will enter the bridge before the message exiting the bridge is printed.
No threads will be needlessly blocked if notifyAll() is replaced with notify()
Week 5 Quiz – Assessed Coursework, Deadline 10:00am 25/02/2019
For each of the following scenarios use the Banker’s algorithm to determine whether the system is in a safe or an unsafe state. If the system is safe, give the safe order that Banker’s algorithm would produce for the processes (you should assume that ties are broken by selecting the process with the smallest number when multiple processes are able to run). If the system is not in a safe state, give the order processes that have executed were executed in, and ll the remaining boxes with X. All allocations and requirements are specied for three resources in the order R1, R2, R3.
Scenario 1:
P0 max requirement 0,3,2 and allocation 0,1,1. P1 max requirement 2,0,0 and allocation 0,0,0. P2 max requirement 3,8,0 and allocation 0,4,0. P3 max requirement 0,7,4 and allocation 0,1,0. P4 max requirement 2,0,1 and allocation 0,0,0.
The current resource availability is:3,2,3. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
Scenario 2:
P0 max requirement 4,3,1 and allocation 0,1,0. P1 max requirement 0,3,0 and allocation 0,0,0. P2 max requirement 4,1,3 and allocation 2,0,0. P3 max requirement 0,1,0 and allocation 0,0,0. P4 max requirement 0,4,2 and allocation 0,1,1.
The current resource availability is:2,2,2. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
The correct answers are: Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one., Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock., If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should.
Question 1 Correct Mark 20.00 out of 20.00 Flag question
Unsafe
P0
P1
P4
X
X
Unsafe

P3
X
X
X
X
Scenario 3:
P0 max requirement 7,2,2 and allocation 1,0,1. P1 max requirement 4,4,1 and allocation 0,0,0. P2 max requirement 0,1,2 and allocation 0,0,0. P3 max requirement 2,0,2 and allocation 0,0,0. P4 max requirement 0,0,3 and allocation 0,0,1.
The current resource availability is:6,4,1. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
Select whether each of the following statements is true or false:
It is realistic to assume that we know the resource requirements of all processe up front in a modern operating system .
Safe
P0
P1
P2
P3
P4
Question 2 Partially correct Mark 7.50 out of 10.00 Flag question
True
deadlock only occurs when all interleavings of a program lead to deadlock
If the system is in a safe state there can never be deadlock . Deadlock can occur in a system that has only one resource .
.
False
True
False
You have correctly selected 3.
The correct answer is:
Select whether each of the following statements is true or false:
It is realistic to assume that we know the resource requirements of all processe up front in a modern operating system [False]. deadlock only occurs when all interleavings of a program lead to deadlock [False].
If the system is in a safe state there can never be deadlock [True].
Deadlock can occur in a system that has only one resource [False].
Question 3 Correct Mark 10.00 out of 10.00 Flag question
Consider the following code:

public class myFirstThread extends Thread
{
Semaphore s1,s2,s3;
public myFirstThread(Semaphore a,
Semaphore b,
s1 = a;
s2 = b;
s3 = c;
}
public void run(){
Semaphore c){
//first thread implementation
}
}
public class mySecondThread extends Thread
{
Semaphore s1,s2,s3;
public mySecondThread (Semaphore a,
Semaphore b,
s1 = a;
s2 = b;
s3 = c;
}
public void run(){
Semaphore c){
//second thread implementation
}
}
public static void main(String[] args){
}
Semaphore s1 = new Semaphore(1);
Semaphore s2 = new Semaphore(2);
Semaphore s3 = new Semaphore(1);
Thread t1 = new myFirstThread(s1,s2,s3);
Thread t2 = new mySecondThread(s1,s2,s3);
t1.start();
t2.start();
Which of the following pairs of implementations of the run methods can deadlock? Exception handling code (try, catch) has been omitted for clarity.
rst thread implementation
second thread implementation
a
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s2.release();
}
b
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s1.acquire();
s3.acquire();
s3.release();
s1.release();
}
c
public void run(){
s1.acquire();
s3.release();
}
public void run(){
s3.acquire();
s1.release();
}
d
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
e
public void run(){
s1.acquire();
s1.release();
}
public void run(){
s3.acquire();
s3.release();
}
f
public void run(){
s2.acquire();
s1.acquire();
s1.release();
s2.release();
}
public void run(){
s1.acquire();
s2.acquire();
s2.release();
s1.release();
}

g
public void run(){
s1.acquire();
s3.acquire();
s1.release();
s3.release();
}
public void run(){
s1.acquire();
s1.release();
}
Select one or more:
a Correct! Since s1 is not signalled by t2 after being acquired it will become zero and both threads could end up waiting for it.
b What happens if t1 acquires s1 then t2 acquires s3? c
d
e
f g
The correct answers are: a, b
Question 4 Partially correct Mark 6.67 out of 10.00 Flag question
public class Buffer {
ArrayList messages;
public Buffer(){
messages = new ArrayList();
messages.add(“Hello”);
messages.add(“World”);
}
public synchronized void
moveFirstItemTo(Buffer other){
if(!messages.isEmpty()){
other.addItem(messages.remove(0));
} }
public synchronized void
addItem(String message){
messages.add(message);
}
}
public class BufferUser extends Thread {
Buffer b1;
Buffer b2;
public BufferUser(Buffer firstBuffer,
Buffer secondBuffer){
b1 = firstBuffer;
b2 = secondBuffer;
}
public void run(){
while(true){
b1.moveFirstItemTo(b2);
}
} }
public static void main(String[] args) {
Buffer b1 = new Buffer();
Buffer b2 = new Buffer();
BufferUser t1 = new BufferUser(b1,b2);
BufferUser t2 = new BufferUser(b2,b1);
t1.start();
t2.start();
}

Select one or more:
a. This program is guaranteed to deadlock.
b. This program will almost certainly deadlock if ran for long enough.
c. This program is unlikely to deadlock in a short time period. d. This program can never deadlock.
e. If the keyword synchronized was removed from the addItem method the program could not deadlock. f. If the keyword synchronized was removed from the addItem method loss of data could occur.
Consider the following concurrent program:
Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 .
p1,p2,p3,q1,q2,q3 . p1,p2,q1,q2,p3,q3 . p1,q1,p2,p3,q2,q3 .
The correct answers are: This program will almost certainly deadlock if ran for long enough., If the keyword synchronized was removed from the addItem method the program could not deadlock., If the keyword synchronized was removed from the addItem method loss of data could occur.
Question 5 Correct Mark 10.00 out of 10.00 Flag question
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Leads to Deadlock Does not Necessarily Lead to Deadlock Leads to Deadlock Does not Necessarily Lead to Deadlock The correct answer is: Consider the following concurrent program: Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 [Leads to Deadlock]. p1,p2,p3,q1,q2,q3 [Does not Necessarily Lead to Deadlock]. p1,p2,q1,q2,p3,q3 [Leads to Deadlock]. p1,q1,p2,p3,q2,q3 [Does not Necessarily Lead to Deadlock]. boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Question 6 Partially correct Mark 5.00 out of 10.00 Flag question The number of possible interleavings of i threads (assuming all interleavings are valid) is given by the formula: (n1+n2 + ... + ni)!/(n1!*n2!*...*ni!)) where ni is the number of atomic instructions in thread i. Assuming each line of the following program represents an atomic instruction complete the following statement: There are possible interleavings of this program of which lead to deadlock. For each of the following scenarios use the Banker's algorithm to determine whether the system is deadlocked. If the system is deadlocked, give the processes involved in the deadlock; if not set all to X. All allocations and requests are specied for three resources in the order R1, R2, R3. Scenario 1: P0 requested 0,2,0 and allocation 1,0,0. P1 requested 2,0,2 and allocation 0,0,0. P2 requested 1,1,2 and allocation 0,0,0. P3 requested 0,0,1 and allocation 0,1,0. P4 requested 0,0,0 and allocation 1,1,2. The current resource availability is: 0,0,0. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Scenario 2: P0 requested 1,1,0 and allocation 0,0,0. P1 requested 2,0,2 and allocation 0,0,0. P2 requested 1,0,1 and allocation 0,1,0. P3 requested 0,0,0 and allocation 2,1,2. P4 requested 0,0,1 and allocation 0,0,0. The current resource availability is: 0,0,1. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Scenario 3: boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false 20 4 Question 7 Partially correct Mark 14.44 out of 20.00 Flag question Not Deadlocked X X X X X Not Deadlocked X X P0 requested 0,0,0 and allocation 0,1,0. X X X P1 requested 2,2,2 and allocation 1,0,0. P2 requested 1,2,0 and allocation 0,0,1. P3 requested 1,0,1 and allocation 0,0,0. P4 requested 1,0,1 and allocation 1,0,0. The current resource availability is: 0,2,1. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Which of the following resource allocation graphs represent a deadlocked system? ab cd Select one: a, b and d only. b. c and d only. None of them. d only. c and d only b and d only. a and b only. All of them. a, c and d only. Not Deadlocked X X X X Question 8 Correct Mark 10.00 out of 10.00 Flag question X The correct answer is: c and d only Week 6 Quiz - Deadline 10:00 am on Tuesday 03/3/2020 Question 1 Correct Mark 5.00 out of 5.00 Flag question Absolute code can be generated for : Select one: a. interrupt binding b. excution-time binding c. load-time binding d. compile-time binding ---------------------- is the method of binding instructions and data to memory performed by most general-purpose operating systems. Select one: a. Execution time binding b. Compile time binding c. Load-time binding d. Interrupt binding Your answer is correct. The correct answer is: compile-time binding Question 2 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: Execution time binding Question 3 Correct Mark 5.00 out of 5.00 Flag question Suppose a program is operating with execution-time binding and the physical address generated is 300. The relocation register is set to 100. What is the corresponding logical address? Select one: a. 100 b. 200 c. 300 d. 199 Your answer is correct. The correct answer is: 200 Question 4 Correct Mark 5.00 out of 5.00 Flag question The mapping of a logical address to a physical address is done in hardware by the ________. Select one: a. relocation register b. dynamic loading register c. memory address register d. memory-management-unit (MMU) Your answer is correct. The correct answer is: memory-management-unit (MMU) Question 5 Correct Mark 5.00 out of 5.00 Flag question _____ is the dynamic storage-allocation algorithm which results in the smallest leftover hole in memory. Select one: a. First t b. Best t c. None of the options d. Worst t Your answer is correct. The correct answer is: Best t Question 6 Correct Mark 5.00 out of 5.00 Flag question The roll out, roll in variant of swapping is used ____. Select one: a. for the round-robin scheduling algorithm b. for priority-based scheduling algorithms c. when a backing store is not necessary d. when the load on the system has temporarily been reduced This question is about contiguous memory allocation, where memory is divided into used and unused blocks of memory, of varying sizes. Which of the following statements about contiguous memory allocation are true: Your answer is correct. The correct answer is: for priority-based scheduling algorithms Question 7 Partially correct Mark 3.33 out of 5.00 Flag question Select one or more: a. Contiguous memory allocation suers from external fragmentation Correct! b. In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100. c. When using contiguous memory allocation for processes, compaction can be used to x external fragmentation Correct! By moving processes from one memory location to another, we can get rid of the fragmentation between blocks of allocated memory. d. Round-robin scheduling relies on contiguous memory allocation The correct answers are: Contiguous memory allocation suers from external fragmentation, In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100., When using contiguous memory allocation for processes, compaction can be used to x external fragmentation Question 8 Partially correct Mark 6.50 out of 10.00 Flag question Consider the following Java code: 1325: public class SomeCode { 1326: 1327: 1328: 1329: 1330: 1331: 1332: 1333: 1334: 1335: 1336: 1337: 1338: 1339: 1340: 1341: 1342: 1343: 1344: 1345: 1346: 1347: 1348: 1349: 1350: public static int v = 9; public static int w = 4; public static void a() { int t =7; v=v +t; t=t *2; w=w +t; b(t); System.out.println(v + w); param) { } public static void b(int int s=9; for (inti=0;i<3;++i){ s=s+param; } v= v+1; // What is on the stack here? } public static void main(String[] args) { int douglas = 40; douglas = douglas + 2; a(); System.exit(0); } } What is printed to the screen when this code executes? What values are on the stack when execution reaches line 1342? Start lling in these boxes at the right hand side -- i.e. the item on the bottom of the stack goes in the rightmost box. If there are more boxes than you need, then ll the spare left-hand boxes with 0. Note, you should enter the values of variables on the stack, not their names; and you don't need to include the 'args[]' passed to main(). Which of the following statements about paged memory allocation are true? Select one or more: a. Using paging can lead to external fragmentation between frames of allocated memory. b. Every call to 'new' requests another frame of memory, to store the resulting object. c. Paging is based on diving memory into frames, the size of which are a power of two Correct! (The power of two bit is important.) d. When using paging, logical addresses are split into a page number, and an oset Correct! The top-most bits are the page number; the bottom-most bits are the oset. For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? 35 0 0 0 0 0 51 14 14 42 Question 9 Correct Mark 5.00 out of 5.00 Flag question The correct answers are: Paging is based on diving memory into frames, the size of which are a power of two, When using paging, logical addresses are split into a page number, and an oset Question 10 Correct Mark 10.00 out of 10.00 Flag question 216 12 288 Your answer is correct. The correct answer is: For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? [12] The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? [216] • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? [288] Question 11 Correct Mark 5.00 out of 5.00 Flag question There is a 1:1 correspondence between the number of entries in the TLB and the number of entries in the page table. Select one: a. TRUE b. FALSE _____ is the dynamic storage-allocation algorithm which results in the largest leftover hole in memory. Select one: a. First t b. Worst t c. Best t Your answer is correct. The correct answer is: FALSE Question 12 Correct Mark 5.00 out of 5.00 Flag question d. None of the above Your answer is correct. The correct answer is: Worst t Question 13 Correct Mark 5.00 out of 5.00 Flag question Assume a system has a TLB hit ratio of 90%. It requires 15 nanoseconds to access the TLB, and 85 nanoseconds to access main memory. What is the eective memory access time in nanoseconds for this system? Select one: a. 22 b. 176.4 c. 108.5 d. 100 Your answer is correct. The correct answer is: 108.5 Question 14 Correct Mark 5.00 out of 5.00 Flag question Consider a logical address with 18 bits used to represent an entry in a conventional page table. How many entries are in the conventional page table? Select one: a. 1024 b. 262144 c. 1048576 d. 18 Your answer is correct. The correct answer is: 262144 Question 15 Correct Mark 5.00 out of 5.00 Flag question Assume the value of the base and limit registers are 1200 and 350 respectively. Which of the following addresses is legal? Select one: a. all of the above b. 355 c. 1200 d. 1551 Your answer is correct. The correct answer is: 1200 Question 16 Correct Mark 5.00 out of 5.00 Flag question What is the context switch time, associated with swapping, if a disk drive with a transfer rate of 2 MB/s is used to swap out part of a program that is 200 KB in size? Assume that no seeks are necessary and that the average latency is 15 ms. The time should reect only the amount of time necessary to swap out the process. Select one: a. 120 ms b. 100 ms c. None of the options d. 113 ms Your answer is correct. The correct answer is: 113 ms Question 17 Correct Mark 5.00 out of 5.00 Flag question What is the advantage of using dynamic loading? Select one: a. With dynamic loading a program does not have to be stored, in its entirety, in main memory b. All of the options are correct c. dynamic loading allows the system to obtain better memory-space utilization d. dynamic loading allows unused routines to stay out of main memory so that memory can be used more eectively Hierarchical page tables are appropriate for 64-bit architectures. Select one: a. FALSE b. TRUE Your answer is correct. The correct answer is: All of the options are correct Question 18 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: FALSE Information Flag question This is the end of the quiz questions - submit your work when you are happy. Remember, once you have pressed submit, you cannot change your answers. Week 7 Coursework - KEATS Quiz, Deadline 10:00 am Tuesday 10/03/2020 A 32-bit computer has a virtual-memory space of 2^32 bytes. The computer is using memory paging, and the page size is 2^9 (i.e. 512) bytes. How many bits of the memory address are used for the page number? How many bits of the memory address are used for the oset? If each physical memory address is stored in 32-bits (i.e. 2^2 bytes), how large is the page table, in bytes? Give your answer as a power of two - e.g. if your answer is (2^10), then enter 10 into the box. Page table size = 2^ bytes. Consider a system with 3 frames of memory and the following sequence of page accesses: 0, 2, 1, 0, 3, 1, 0, 2, 3, 2, 3, 1, 0, 3, 1 When do page faults occur using the FIFO and LRU page replacement algorithms? Enter your answer as a string, comprising the letters Y and N, where Y means there was a page fault, and N means there was not. For instance, if you think there were three page faults to start with, and then no page faults after that, enter YYYNNNNNNNNNNNN Do not include any spaces or punctuation in your answer. FIFO Page faults: LRU Page faults: Thrashing is bad, m'kay. But which of the following would the situation worse, better, or have no eect at all? Adding a bigger hard drive will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Question 1 Correct Mark 20.00 out of 20.00 Flag question 23 9 25 Question 2 Incorrect Mark 0.00 out of 20.00 Flag question Information Flag question YYYNYNYYNNYNYN YYYNYNNYYNYYNN Question 3 Correct Mark 5.00 out of 5.00 Flag question c. Have no eect on the amount of thrashing Correct - a bigger hard drive would have more free space, but the bottleneck is the time taken to swap pages to/from disk. Terminating some processes (closing some programs) will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we terminate some processes, then memory is freed up, reducing the amount of thrashing. c. Have no eect on the amount of thrashing Adding more memory to the machine will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - adding more memory increases how much memory each process can use, reducing the number of page faults, and hence reducing thrashing. c. Have no eect on the amount of thrashing Rewriting code to have a smaller working set (locality) will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we can get the total working set size to be less than the amount of physical memory in the machine, we can hope to eliminate thrashing. c. Have no eect on the amount of thrashing In systems that support virtual memory, ____. Select one: The correct answer is: Have no eect on the amount of thrashing Question 4 Correct Mark 5.00 out of 5.00 Flag question The correct answer is: Reduce the amount of thrashing Question 5 Correct Mark 5.00 out of 5.00 Flag question The correct answer is: Reduce the amount of thrashing Question 6 Correct Mark 5.00 out of 5.00 Flag question The correct answer is: Reduce the amount of thrashing Question 7 Correct Mark 5.00 out of 5.00 Flag question a. physical memory is separated from logical memory. b. virtual memory is separated from logical memory. c. virtual memory is separated from physical memory. d. physical memory is separated from secondary storage. Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what is the number of page faults for the given reference string? Select one: 14 8 13 10 Your answer is correct. The correct answer is: physical memory is separated from logical memory. Question 8 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: 8 Question 9 Correct Mark 10.00 out of 10.00 Flag question Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what will be the nal conguration of the three frames following the execution of the given reference string? Select one: a. 4, 2, 3 b. 4, 1, 3 c. 3, 4, 2 d. 3, 1, 4 Belady's anomaly states that ____. Select one: a. for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases b. for some page replacement algorithms, the page-fault rate may decrease as the number of allocated frames increases Your answer is correct. The correct answer is: 3, 4, 2 Question 10 Correct Mark 5.00 out of 5.00 Flag question c. giving more memory to a process will improve its performance d. as the number of allocated frames increases, the page-fault rate may decrease for all page replacement algorithms Your answer is correct. The correct answer is: for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases Question 11 Correct Mark 5.00 out of 5.00 Flag question Optimal page replacement ____. Select one: is used mostly for comparison with other page-replacement schemes requires that the system keep track of previously used pages can suer from Belady's anomaly is the page-replacement algorithm most often implemented Your answer is correct. The correct answer is: is used mostly for comparison with other page-replacement schemes Question 12 Correct Mark 5.00 out of 5.00 Flag question _____ is the algorithm implemented on most systems. Select one: FIFO Most frequently used Least frequently used LRU Week 8 Coursework - Deadline: 10:00, 20th of March 2020 Which of the following two statements are security problems that can arise and need to be protected against when users simultaneously share a computing system -- i.e. they would not otherwise be an issue on a single-user system Select one or more: a. Users can accidentally delete their les from disk Your answer is correct. The correct answer is: LRU Question 1 Correct Mark 5.00 out of 5.00 Flag question b. One user's process might access the memory of another user's process Yes, in principle, if one user's process accessed the memory of another user's process, it could, for instance, look at what document they were currently editing. c. Condential les kept on disk could be accessed by any user It's important to use access control to ensure users can have private les that only they (and systems administrators) can access. d. The system might start to run unacceptably slowly An advantage of compiler-based enforcement of access control is privileges are closely related to the concept of a data type. The correct answers are: One user's process might access the memory of another user's process, Condential les kept on disk could be accessed by any user Question 2 Correct Mark 5.00 out of 5.00 Flag question access linguistic Your answer is correct. The correct answer is: An advantage of compiler-based enforcement of access control is[access] privileges are closely related to the [linguistic ] concept of a data type. Question 3 Correct Mark 5.00 out of 5.00 Flag question The normally decide the contents of the access-matrix entries. users Your answer is correct. The correct answer is: The [users] normally decide the contents of the access-matrix entries. Question 4 Correct Mark 5.00 out of 5.00 Flag question The for both the and association between processes and domains. access matrix provides an appropriate mechanism for defining and implementing strict control static Your answer is correct. The correct answer is: The [access matrix] provides an appropriate mechanism for defining and implementing [strict control] for both the [static] and [dynamic] association between processes and domains. Question 5 Correct Mark 5.00 out of 5.00 Flag question dynamic it is difficult to take advantage of special groupings of objects or domains when implementing using a access matrix global table Your answer is correct. The correct answer is: it is difficult to take advantage of special groupings of objects or domains when implementing [access matrix] using a [global table] Question 6 Incorrect Mark 0.00 out of 5.00 Flag question Process P should be able to switch from domain Di to domain Dj if and only if the Your answer is incorrect. The correct answer is: Process P should be able to switch from domain Di to domain Dj if and only if the [access right] [switch ] ∈ access(i, j). The ∈ access(i, j). rights allow a process to change the entries in a column in the access matrix and the control Most systems use a combination of the . When a process rst tries to access an object, is searched. If access is denied, an exception condition occurs. Otherwise, a rights applicable to objects only. domain switch access right Question 7 Partially correct Mark 2.67 out of 4.00 Flag question control Your answer is partially correct. You have correctly selected 2. The correct answer is: The [copy and owner] rights allow a process to change the entries in a column in the access matrix and the [control ] rights applicable to [domain] objects only. Question 8 Correct Mark 5.00 out of 5.00 Flag question The accessed by list is a object maintained by and only . capability protected operating system users indirectly Your answer is correct. The correct answer is: The [capability] list is a [protected ]object maintained by [operating system ]and accessed by [users] only [indirectly]. Question 9 Partially correct Mark 3.33 out of 5.00 Flag question access list access list and global table capability is created and attached to the process. Question 10 Correct Mark 3.00 out of 3.00 Flag question Enforcement by enforcement by the is than programming languages more exible kernel for user-dened policy Your answer is correct. The correct answer is: Enforcement by [kernel ] is [less] [exible] than enforcement by the [programming languages ] for user-dened policy Comment: Question 11 Correct Mark 3.00 out of 3.00 Flag question In , when a class is domain that gives the , the of that class. assigns the class to a Java loaded JVM protection Your answer is correct. The correct answer is: In [Java], when a class is [loaded], the [JVM] assigns the class to a [protection ] domain that gives the [permissions ] of that class. Question 12 Correct Mark 5.00 out of 5.00 Flag question A problem is the problem of can migrate outside of its execution environment. permissions connement guaranteeing that no initially held in an information object Your answer is partially correct. You have correctly selected 2. The correct answer is: Most systems use a combination of [access list and capabilities ] . When a process rst tries to access an object, the [access list ] is searched. If access is denied, an exception condition occurs. Otherwise, a [capability ] is created and attached to the process. Your answer is correct. The correct answer is: Question 13 Correct Mark 5.00 out of 5.00 Flag question The principle of least means that programs, users, and even systems be given privileges to perform their . privileges just enough tasks Your answer is correct. The correct answer is: The principle of least [privileges] means that programs, users, and even systems be given [just enough] privileges to perform their [tasks]. Question 14 Correct Mark 5.00 out of 5.00 Flag question Windows 2000 has a complex protection scheme at its core and yet has many security holes. Your answer is correct. The correct answer is: [Windows 2000] has a complex protection scheme at its core and yet has many security holes. Question 15 Incorrect Mark 0.00 out of 5.00 Flag question The principle, is useful in limiting the amount of damage a faulty process can cause in the system. least-privilged Your answer is incorrect. The correct answer is: The [need‐to‐know] principle, is useful in limiting the amount of damage a faulty process can cause in the system. Question 16 Correct Mark 5.00 out of 5.00 Flag question The association between a and a may be either or . process domain static dynamic Your answer is correct. The correct answer is: The association between a [process] and a [domain]may be either [static ] or [dynamic]. A[connement] problem is the problem of [ guaranteeing] that no [information] initially held in an [object] can migrate outside of its execution environment. Question 17 Correct Mark 5.00 out of 5.00 Flag question In the system, the protection domains are organized hierarchically into a . MULTICS ring structure Your answer is correct. The correct answer is: In the [MULTICS] system, the protection domains are organized hierarchically into a [ring structure]. Question 18 Correct Mark 5.00 out of 5.00 Flag question Which of the following statements is not TRUE about Compiler Based Enforcement? Select one: Protection is embedded in linguistic concept of data type. Protection requirements can be dened independently of any particular operating system facilities. The means for enforcement need to be provided by the designer of a subsystem. Protection needs are declared, rather than programmed. Stack inspection is : Select one: Providing methods to request access to a protected resource either directly or indirectly Protection mechanism provided in Java programming language All the options are correct Useful for inspecting classes from un trusted sources Consider the following le-access-control situations. For each, choose whether it could be encoded using the standard UNIX owner/group/other permissions model - and if so, choose appropriate users, groups and permissions If you do not think the permissions can be written in owner/group/other format, choose 'No' then pick the 'It cannot be done' option for the other answers to that question. Your answer is correct. The correct answer is: The means for enforcement need to be provided by the designer of a subsystem. Question 19 Partially correct Mark 1.67 out of 5.00 Flag question Your answer is partially correct. The correct answer is: All the options are correct Question 20 Correct Mark 10.00 out of 10.00 Flag question a) Harry creates a le. He wants to give read/write access to Ron and Hermione, and no access to anyone else. Can this be done using the owner/group/other model? Yes If so: Who would be the owner of the le? Who would be in the group for the le? Ron: Hermione: What would their permissions be? What would the 'other' permissions be? b) Voldemort creates a le. He wants to give Snape read/write access, Bellatrix read-only access, and no access to anyone else. Can this be done using the owner/group/other model? If so: Who would be the owner of the le? Who would be in the group for the le? Snape: Bellatrix: What would their permissions be? What would the 'other' permissions be? c) Filch creates a le. He wants to give sta read/write access, and other users (e.g. pupils) read-only access. Can this be done using the owner/group/other model? If so: Who would be the owner of the le? Who would be the group for the le? What would their permissions be? What would the 'other' permissions be? Week 9 Quiz - Extended Deadline 10:00, March the 30th for students who have been in isolation due to corona virus. Harry Yes Yes rw- --- No Neither/it cannot be done No/it cannot be done No/it cannot be done Neither/it cannot be done Filch Neither/it cannot be done Yes Sta rw- r-- Question 1 Correct Mark 10.00 out of 10.00 Flag question A is structured as a complete, standalone program whereas a is a fragment of code embedded in a legitimate program. worm virus Your answer is correct. The correct answer is: A [worm]is structured as a complete, standalone program whereas a [virus] is a fragment of code embedded in a legitimate program. Question 2 Correct Mark 8.00 out of 8.00 Flag question The concept "system reliability" means: Select one: The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. None of the three options The Probability of a system that will be functioning correctly at any given time The Probability of a system that will be functioning without errors during daytime Your answer is correct. The correct answer is: The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. Question 3 Correct Mark 10.00 out of 10.00 Flag question ----------- is a symmetric stream cipher Select one: AES RC4 None of the three options DES Limit privileged user functionality means: Select one: Users with ‘normal’ privileges should be prevented from installing or disabling any software or services running on the system. Users with privileged system rights have constrained internet and email access from their privileged account None of the three options Administrators have full internet and email access from their privileged account Your answer is correct. The correct answer is: RC4 Question 4 Correct Mark 8.00 out of 8.00 Flag question Your answer is correct. The correct answer is: Users with privileged system rights have constrained internet and email access from their privileged account Question 5 Correct Mark 10.00 out of 10.00 Flag question A code segment that misuses its environment is called Select one: a Trojan horse a trap door a worm a back door The backdoor program is Select one: Used in distributed attacks that focus on the malicious modication to software/hardware at the factory time. All the three options Used to gain unauthorized access to information Used in distributed attacks that focus on the malicious modication to software/hardware at the distribution time In a paired-password system, Select one: the user species two passwords passwords must contain equal amounts of numbers and digits paired together the computer supplies one part of a password and the user enters the other part two users must enter their own separate password to gain access to the system Your answer is correct. The correct answer is: a Trojan horse Question 6 Correct Mark 8.00 out of 8.00 Flag question Your answer is correct. The correct answer is: All the three options Question 7 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: the computer supplies one part of a password and the user enters the other part Question 8 Correct Mark 10.00 out of 10.00 Flag question A worm Select one: continue to grow as the Internet expands use the spawn mechanism to ravage system performance All the three options can shut down an entire network Your answer is correct. The correct answer is: All the three options Question 9 Partially correct Mark 7.20 out of 8.00 Flag question boot virus infects the virus changes the start of the program so that execution jumps to its is written in level programming languages. virus includes code along with the encrypted virus. virus attempts to bypass detection by an antivirus by installing itself in the chain boot sector of the system A A An . le code macro low encrypted Tunneling decryption interrupt handler Your answer is partially correct. You have correctly selected 9. The correct answer is: [boot] virus infects the [boot] sector of the system A [le] virus changes the start of the program so that execution jumps to its [code]. A [macro] is written in [high] level programming languages. An [encrypted] virus includes [decryption]code along with the encrypted virus. [Tunneling ] virus attempts to bypass detection by an antivirus by installing itself in the [interrupt handler ] chain Question 10 Correct Mark 8.00 out of 8.00 Flag question Which of the following attacks is not type of social engineering attacks ? Select one: Baiting Phishing Pretexting D-denial of service Your answer is correct. The correct answer is: D-denial of service Question 11 Partially correct Mark 6.67 out of 10.00 Flag question Modern is based on called that are selectively distributed to computers in a network and used to process messages. Cryptography tokens keys Your answer is partially correct. You have correctly selected 2. The correct answer is: Modern [Cryptography] is based on [secrets] called [keys]that are selectively distributed to computers in a network and used to process messages. Week 10 Coursework - Deadline is extended to 10:00, 3'rd of April UNIX process management separates the creation of and the running of a new program into two distinct operations. system call a new process and a new program is run after a system call to . Question 1 Correct Mark 10.00 out of 10.00 Flag question processes fork creates execve Your answer is correct. The correct answer is: UNIX process management separates the creation of [processes] and the running of a new program into two distinct operations. [fork] system call [creates ] a new process and a new program is run after a system call to [execve] . Question 2 Correct Mark 10.00 out of 10.00 Flag question Which of the following statements is TRUE about Linux virtual manager? Select one: The VM manager creates a new virtual address space when there is a fork system call The VM manager creates a new virtual address space when there is a exec system call The VM manager maintains logical and physical views of a process’s address space All of the options Which of the following statements is TRUE about Linux Threads? Select one: A thread is a new process that has its own address space Fork creates a new process with its own identity, but that is allowed to share the data structures of its parent Linux uses the same internal representation for processes and threads All of the three options Your answer is correct. The correct answer is: All of the options Question 3 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: Linux uses the same internal representation for processes and threads Question 4 Correct Mark 10.00 out of 10.00 Flag question Fill in the missing words: In Linux, a is a command that allows users to type commands from the keyboard to interact with the operating system . It is a computer program that the commands the user types and sends them to the operating system. Furthermore, it provides a environment consisting of environment . Shell interpreter kernel interprets programming variables Your answer is correct. The correct answer is: Fill in the missing words: In Linux, a [Shell] is a command [interpreter ] that allows users to type commands from the keyboard to interact with the operating system [kernel]. It is a computer program that [interprets ] the commands the user types and sends them to the operating system. Furthermore, it provides a [programming ] environment consisting of environment [variables ]. Question 5 Correct Mark 10.00 out of 10.00 Flag question The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with access to the the resources of the computer. Its code and data structures are kept in the space. address full all physical same single Your answer is correct. The correct answer is: The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with [full] access to the [all] the [physical ] resources of the computer. Its code and data structures are kept in the [same] [single ] address space. Question 6 Partially correct Mark 3.33 out of 10.00 Flag question Which of the following is TRUE about keeping functionality in shared libraries rather than in the kernel itself? Select one: Performance Manageability Reliability All of the options Your answer is partially correct. The correct answer is: All of the options Question 7 Correct Mark 10.00 out of 10.00 Flag question Which of the following statements is TRUE about The Linux source code is freely and widely available over the Internet and from CD-ROM vendors? Select one: Linux’s source code is open to scrutiny by both the good guys and the bad guys. Open source code implies both that security weaknesses can be found and xed faster by the Linux community, increasing the security of the system; and that attackers can more easily nd any weaknesses that do remain in Linux. Attackers’ jobs are made easier if they have access to the source code of the system they are trying to penetrate All of the options Question 8 Correct Mark 10.00 out of 10.00 Flag question Select the Missing words: In Linux, are implemented within the creates a new process within the same virtual address space as the by a mechanism that threads kernel clone parent process. Your answer is correct. The correct answer is: Select the Missing words: In Linux, [threads] are implemented within the [kernel] by a [clone] mechanism that creates a new process within the same virtual address space as the [parent ] process. Question 9 Correct Mark 10.00 out of 10.00 Flag question Which of the following statements is TRUE about Linux schedular? Select one: All of the options Processes are assigned priorities that are based on the nice value only. Processes with shorter sleep times are often CPU-bound and thus will have higher priorities. The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. Which of the following sentences is TRUE about writing an operating system using high-level programming languages ? Select one: All of the options High-level programming languages have powerful programming environments that include tools such as debuggers and performance prolers that could be handy for developing code. Your answer is correct. The correct answer is: The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. Question 10 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: All of the options The number of programming errors is reduced as the code becomes more compact High-level languages may provide advanced features such as bounds checking that further minimize programming errors and security loopholes. Your answer is correct. The correct answer is: All of the options Quiz -1 Assessed Coursework, Deadline 10:00am Tuesday 28/01/2020 Question 1 Partially correct Mark 8.00 out of 10.00 Flag question Select whether each of the following statements is true or false: An interrupt causes a process to go from a ready to a running state A process is an unchanging static collection of instructions A process can move directly from a waiting state to a ready state A process can move directly from a new to a running state A stack overow can occur because a recursive method calls itself many times True False True You have correctly selected 4. The correct answer is: Select whether each of the following statements is true or false: An interrupt causes a process to go from a ready to a running state [False] A process is an unchanging static collection of instructions [False] A process can move directly from a waiting state to a ready state [True] A process can move directly from a new to a running state [False] A stack overow can occur because a recursive method calls itself many times [True] Question 2 Correct Mark 10.00 out of 10.00 Flag question Schedule the following processes using rst come rst served scheduling: P0 duration: 6 arrives: 1 priority: 1 P1 duration: 7 arrives: 5 priority: 5 P2 duration: 4 arrives: 10 priority: 10 P3 duration: 2 arrives: 6 priority: 6 P4 duration: 5 arrives: 0 priority: 0 What is the total waiting time? Answer: 32 Correct! Well Done, you won't need the hints below. Hint: each process runs until it nishes, processes start in the order they arrived, see the lecture notes for more details The correct answer is: 32 Question 3 Correct Mark 10.00 out of 10.00 Flag question When using migration in multiprocessing idle processors take jobs from the queues of busy processors. The average turnaround time for round robin scheduling the length of the quantum. P1 (duration 19) P2 (duration 7) P3 (duration 4) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the False True / processes arrive in the order . In scheduling. multiprocessing one processor does all the Correct, well done! The correct answer is: When using [pull] migration in multiprocessing idle processors take jobs from the queues of busy processors. The average turnaround time for round robin scheduling [depends on] the length of the quantum. P1 (duration 19) P2 (duration 7) P3 (duration 4) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order [P3] [P2] [P1]. In [asymmetric] multiprocessing one processor does all the scheduling. Question 4 Correct Mark 15.00 out of 15.00 Flag question Schedule the following processes using pre-emptive priority scheduling: P0 duration: 10 arrives: 15 priority: 17 P1 duration: 10 arrives: 0 priority: 7 P2 duration: 13 arrives: 18 priority: 5 P3 duration: 3 arrives: 8 priority: 8 P4 duration: 7 arrives: 6 priority: 10 Fill in the schedule below: Process Start Time Runs For P1 0 10 P3 10 3 P4 13 5 P2 18 13 P4 31 2 P0 33 10 Now complete the waiting and turnaround times for each process, then the total and averages. Process P0 P1 P2 P3 Waiting Time Turnaround Time 18 28 0 10 0 13 2 5 / P4 Total Average 20 27 40 83 8 16.6 The correct schedule is: 0: P1 (10) 10: P3 (3) 13: P4 (5) 18: P2 (13) 31: P4 (2) 33: P0 (10) Waiting times: P0 18 P1 0 P2 0 P3 2 P4 20 Turnaround times : P0 28 P2 13 P4 27 P1 10 P3 5 Question 5 Correct Mark 15.00 out of 15.00 Flag question This question is about multi-queue scheduling. Select all the true statements from the list below: Select one or more: Multi-queue scheduling can be used on single processor systems. Correct! Multi-level feedback queues can be used for priority scheduling. Correct! Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling option is for higher priority queues to have absolute priority, using aging to prevent starvation. In multi-queue scheduling all queues must have the same scheduling algorithm. In Multi-level feedback queue scheduling jobs always stay on the same queue. Correct! Another Correct! Well done. The correct answers are: Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling, Multi-queue scheduling can be used on single processor systems., Multi-level feedback queues can be used for priority scheduling. Information Flag question Information for answering Round Robin Scheduling Questions. If you have a quantum of 3 for example, and a schedule like this: 0: P0 (3) 3: P0 (3) 6: P1 (3) 9: P2 (3) 12: P2 (1) Then don't enter it as above, with the original quanta, but rather include the total time each process is running, so: 0: P0 (6) 6: P1 (3) 9: P2 (4) In your question there wouldn't be enough boxes to do it the rst way round. / Schedule the following processes using round robin scheduling with quantum 10: P0 duration: 20 arrives: 16 P1 duration: 39 arrives: 0 P2 duration: 7 arrives: 22 P3 duration: 20 arrives: 50 P4 duration: 7 arrives: 24 Fill in the schedule below: Process Start Time Runs For P1 0 20 P0 20 10 P1 P2 30 10 40 7 P4 P0 47 7 54 10 P1 64 9 P3 73 93 Now complete the waiting and turnaround times for each process, then the total and averages. Process P0 P1 P2 P3 P4 Total Average Waiting Time Turnaround Time 28 34 48 73 18 23 25 43 23 30 126 25.2 219 43.8 Question 6 Partially correct Mark 14.61 out of 15.00 Flag question The correct schedule is: 0: P1 (20) 20: P0 (10) 30: P1 (10) 40: P2 (7) 47: P4 (7) 54: P0 (10) 64: P1 (9) 73: P3 (20) / Question 7 Partially correct Mark 7.50 out of 10.00 Flag question Select whether each of the following statements is true or false: The priority of real-time tasks in Linux can change . SJF is a good algorithm for short-term scheduling as CPU burst lengths are easy to to predict . A child process always shares the resources of its parent . In multi-level queue scheduling one queue always has absolute priority over other queues . False False False True You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: The priority of real-time tasks in Linux can change [False]. SJF is a good algorithm for short-term scheduling as CPU burst lengths are easy to to predict [False]. A child process always shares the resources of its parent [False]. In multi-level queue scheduling one queue always has absolute priority over other queues [False]. Question 8 Partially correct Mark 8.14 out of 15.00 Flag question Schedule the following processes using shortest remaining time rst scheduling: P0 duration: 11 arrives: 17 P1 duration: 21 arrives: 0 P2 duration: 16 arrives: 15 P3 duration: 10 arrives: 6 P4 duration: 13 arrives: 7 Fill in the schedule below: Process Start Time Runs For P1 0 6 P3 P2 6 10 P0 16 1 17 11 P4 28 13 P1 41 15 P2 56 15 / Waiting times: P0 28 P1 34 P2 18 P3 23 P4 23 Turnaround times : P3 43 P0 48 P4 30 P1 73 P2 25 Now complete the waiting and turnaround times for each process, then the total and averages. Process P0 P1 P2 P3 P4 Total Average Waiting Time Turnaround Time 0 56 35 10 40 0 34 56 21 11 96 19.2 167 33.4 The correct schedule is: 0: P1 (6) 6: P3 (10) 16: P4 (1) 17: P0 (11) 28: P4 (12) 40: P1 (15) 55: P2 (16) Waiting times: P0 0 P1 34 P2 40 P3 0 P4 20 Turnaround times : P3 10 P0 11 P1 55 P2 56 P4 33 Week 2 Quiz - Assessed Coursework, Deadline 10:00am 04/02/2020 Select whether each of the following statements is true or false: A line of Java code usually represents multiple atomic CPU instructions . Java automatically creates a separate thread for a GUI to make sure it remains responsive When a Thread is created using the constructor it enters a runnable state If a thread calls yield() it is terminated . . . Question 1 Partially correct Mark 7.50 out of 10.00 Flag question True True False True You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: A line of Java code usually represents multiple atomic CPU instructions [True]. Java automatically creates a separate thread for a GUI to make sure it remains responsive [True]. When a Thread is created using the constructor it enters a runnable state [False]. If a thread calls yield() it is terminated [False]. Question 2 Incorrect Mark 0.00 out of 20.00 Flag question / A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread r = new Printer("R"); Thread p = new Printer("P"); p.start(); r.start(); try{ p.join(); } catch (Exception e){ e.printStackTrace(); } for(int i = 0; i < 10; ++i){ System.out.print(“Q”); } } } The code for the class Printer is correctly implemented, the class extends Thread and the run method prints out the letter given as an argument to the constructor 10 times (it may, or may not, do other computation that does not produce any output). Which of the following are possible outputs of this program? (to save laborious counting you can safely assume that all answers contain 10Ps, 10Qs and 10Rs). 0: RRRPPPRRPPRPPRRPRPRQPQQQQQQQQQ 1: RRRRRRRRRRPPPPPPPPPPQQQQQQQQQQ 2: QQQQQQQQQQPPPPPPPPPPRRRRRRRRRR 3: RRRRRRRRRRQQQQQQQQQQPPPPPPPPPP 4: RQRQRQRQRQRQRQRQRQRQPPPPPPPPPP 5: RPQRPQRPQRPQRPQRPQRPQRPQRPQRPQ 6: RRRPPPRRPPRPPRRPRPPQQRQQQQQQQQ 7: RPRPRPRPRPRPRPRPRPRPQQQQQQQQQQ 8: PQPQPQPQPQPQPQPQPQPQRRRRRRRRRR 9: PPPPPPPPPPQQQQQQQQQQRRRRRRRRRR Select one: None of the above. 1, 9, 7, 0 and 6 only 1, 3, 7 and 0 only 1, 3 and 4 only 1 and 7 only 1, 9, 7 and 6 only All of the above join() does. 1 only Incorrect. This would be correct if it wasn't for the join() statement, have a look in the lecture slides at what The correct answer is: 1, 9, 7 and 6 only Question 3 Partially correct Mark 7.50 out of 10.00 Flag question / Select whether each of the following statements is true or false: All programs should be multi-threaded. . There is often value in writing threaded code for a machine with only 1 CPU. . The execution of a concurrent program can interleave threads in a dierent way each time. Atomic instructions can be split into a number of smaller instructions. . . False False True False You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: All programs should be multi-threaded. [False]. There is often value in writing threaded code for a machine with only 1 CPU. [True]. The execution of a concurrent program can interleave threads in a dierent way each time. [True]. Atomic instructions can be split into a number of smaller instructions. [False]. Question 4 Correct Mark 15.00 out of 15.00 Flag question In the following solution to the critical section problem (note that the two processes are slightly dierent): boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to . Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to . violation of mutual exclusion starvation of q This program satises the requirement for . It is that p can never starve. Freedom From Deadlock True The correct answer is: In the following solution to the critical section problem (note that the two processes are slightly dierent): boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to [violation of mutual exclusion]. / Question 5 Correct Mark 10.00 out of 10.00 Flag question When reasoning with concurrent programs we assume that no process will terminate in its section. If a single process is executing its preprotocol but is never able to enter its critical section this is called . A solution to the critical section problem must ensure that two processes do not enter their sections at once. Correct, well done! The correct answer is: When reasoning with concurrent programs we assume that no process will terminate in its [critical] section. If a single process is executing its preprotocol but is never able to enter its critical section this is called [starvation]. A solution to the critical section problem must ensure that two processes do not enter their [critical] sections at once. Question 6 Correct Mark 20.00 out of 20.00 Flag question Consider the following solution to the critical section problem: boolean wantp <- false, wantq <- false p q loop_forever p1: non-critical section p2: wantp <- true P3: while wantq p4: wantp <- false P5: wantp <- true p6: critical section p7: wantp <- false loop_forever q1: non-critical section q2: wantq <- true q3: while wantp q4: wantq <- false q5: wantq <- true q6: critical section q7: wantq <- false Which of the three properties does this solution satisfy? Select one: Freedom From Deadlock and Freedom From Starvation only. None. Mutual Exclusion and Freedom From Starvation only. All Three: Mutual Exclusion, Freedom From Starvation, Freedom From Deadlock. Freedom From Starvation Only. Freedom From Deadlock Only. Mutual Exclusion and Freedom From Deadlock only. Correct! Make sure you can give the scenario that leads to starvation. Mutual Exclusion Only. The correct answer is: Mutual Exclusion and Freedom From Deadlock only. / Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to [starvation of q]. This program satises the requirement for [Freedom From Deadlock]. It is [True] that p can never starve. Question 7 Partially correct Mark 7.50 out of 15.00 Flag question A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread p = new Printer("p"); Thread q = new Printer("Q"); p.run(); q.run(); for(int i = 0; i < 10; ++i){ System.out.println("R"); } } } What is the maximum number of threads belonging to this program running at any one time during its execution? Select one: 0 1 2 3 You would be correct, but the programmer has made an error: can you spot it? Week 3 Quiz - Assessed Coursework, Deadline 10:00 am 11/02/2020 Select whether each of the following statements is true or false: Ticket numbers in the bakery algorithm are unbounded. . Starvation can occur in the bakery algorithm if a process exits in its non-critical section. . Setting number[i] to zero after the critical section in the bakery algorithm is important for success in the absence of contention. . The bakery algorithm is ecient for use in practice. . The correct answer is: 1 Question 1 Correct Mark 10.00 out of 10.00 Flag question True False True False Congratulations! The correct answer is: Select whether each of the following statements is true or false: Ticket numbers in the bakery algorithm are unbounded. [True]. Starvation can occur in the bakery algorithm if a process exits in its non-critical section. [False]. Setting number[i] to zero after the critical section in the bakery algorithm is important for success in the absence of contention. [True]. The bakery algorithm is ecient for use in practice. [False]. / Question 2 Correct Mark 10.00 out of 10.00 Flag question Which of the following are valid outputs for the following program: Semaphore S1<- 0, S2 <- 0 p q r p1: print(“p”) p2: signal(S1) p3: signal(S2) q1: wait(S1) q2: print(“q”) r1: wait(S2) r2: print(“r”) Select one or more: qpr pqr Correct! And there's at least one more. qrp rqp prq Good, that was the hard one, the scheduler might permit p1,p2,p3 and then schedule r. rpq Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. The correct answers are: pqr, prq Question 3 Partially correct Mark 17.50 out of 20.00 Flag question Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Solution 1: Solution 2: Solution 3: Mutual Exclusion Only Mutual Exclusion Only FreedomFrom Deadlock Only / Solution 4: Both Solution 5: Solution 6: Solution 7: Solution 8: FreedomFrom Deadlock Only Both Mutual Exclusion Only FreedomFrom Deadlock Only The correct answer is: Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Solution 1: [Both] Solution 2: [Mutual Exclusion Only] Solution 3: [FreedomFrom Deadlock Only] Solution 4: [Both] Solution 5: [FreedomFrom Deadlock Only] Solution 6: [Both] Solution 7: [Mutual Exclusion Only] Solution 8: [FreedomFrom Deadlock Only] Question 4 Correct Mark 20.00 out of 20.00 Flag question Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. / import java.util.concurrent.Semaphore; public class Pedestrian extends safeToCross = private String name; public Pedestrian(String nameIn){ name = nameIn; { Thread static Semaphore public void run() { new Semaphore(2) ; } for(int i = 0; i < 3; ++i){ try{ safeToCross.acquire(); System.out.println("Pedestrian " + name + " Entering the Bridge"); System.out.println("Pedestrian " + name + " Leaving the Bridge"); } catch ( e){ e.printStackTrace(); } Thread.sleep(100); safeToCross.release(); } } public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave. ; Pedestrian pete = new Pedestrian("Pete"); pete. ; Pedestrian jackie = new Pedestrian("Jackie"); jackie. ; Pedestrian jane = new Pedestrian("Jane"); jane. ; } } start() InterruptedException start() start() start() Your answer is correct. The correct answer is: / Question 5 Correct Mark 10.00 out of 10.00 Flag question Select whether each of the following statements is true or false: Test and set is provided by software. . Disabling interrupts is a feasible mechanism for synchronisation in a multi-processor system. . False False / Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends [Thread] { [static Semaphore] safeToCross = [new Semaphore(2)]; private String name; public Pedestrian(String nameIn){ name = nameIn; } [public void run()]{ for(int i = 0; i < 3; ++i){ try{ [safeToCross.acquire();] System.out.println("Pedestrian " + name + " Entering the Bridge"); [Thread.sleep(100);] System.out.println("Pedestrian " + name + " Leaving the Bridge"); [safeToCross.release();] } catch ([InterruptedException] e){ e.printStackTrace(); } } } public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave.[start()]; Pedestrian pete = new Pedestrian("Pete"); pete.[start()]; Pedestrian jackie = new Pedestrian("Jackie"); jackie.[start()]; Pedestrian jane = new Pedestrian("Jane"); jane.[start()]; } } Deadlock cannot occur when using semaphores. . If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. . False True Congratulations! The correct answer is: Select whether each of the following statements is true or false: Test and set is provided by software. [False]. Disabling interrupts is a feasible mechanism for synchronisation in a multi-processor system. [False]. Deadlock cannot occur when using semaphores. [False]. If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. [True]. Question 6 Correct Mark 5.00 out of 5.00 Flag question Which of the three types of semaphore can be used to implement a solution to the critical section problem without the risk of starvation? Select one: Blocked Queue and Blocked Set semaphores only. Blocked Set semaphores only. All of them. Busy Wait Semaphores and Blocked Queue Semaphores. Busy Wait sempahores only. Blocked Queue semaphores only. Correct! Busy Wait Semaphores and Blocked Set Semaphores. None of them. A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain species that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the oor). Complete the following pseudocode model of the problem: The correct answer is: Blocked Queue semaphores only. Question 7 Partially correct Mark 9.00 out of 15.00 Flag question Semaphore CrateOnTrain <- , Semaphore spaceOnTrain <- 10 0 / Loading Crane loop forever: Unoading Crane wait(spaceOnTrain) wait(crateOnTrain) pickup crate from oor unload crate from train signal(crateOnTrain) signal(spaceOnTrain) load crate onto train loop forever: put down crate on oor The correct answer is: A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain species that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the oor). Complete the following pseudocode model of the problem: Semaphore CrateOnTrain <- [10], Semaphore spaceOnTrain <- [0] Loading Crane Unoading Crane loop forever: [pickup crate from oor] [wait(spaceOnTrain)] [load crate onto train] [signal(crateOnTrain)] loop forever: [wait(crateOnTrain)] [unload crate from train] [signal(spaceOnTrain)] [put down crate on oor] Question 8 Partially correct Mark 7.50 out of 10.00 Flag question Consider the following solution to the dining philosophers problem in which ve philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to . Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock . deadlock false / Changing the order in which philosopher t picks up the forks will prevent deadlock . Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock . The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to [deadlock]. Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock [false]. Changing the order in which philosopher t picks up the forks will prevent deadlock [true]. Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock [true]. false true The correct answer is: Consider the following solution to the dining philosophers problem in which ve philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) Week 4 Quiz - Assessed Coursework, Deadline 18/02/2020 @ 10am Consider the follow diagram representing the states of threads in Java when using monitors. Question 1 Correct Mark 10.00 out of 10.00 Flag question StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) (c) (1) (2) (3) Runnable Running start() run() yield() / (4) wait() (5) (6) The scheduler can cause transitions on edges . notifyAll() run() ends 2 and 3 The correct answer is: Consider the follow diagram representing the states of threads in Java when using monitors. StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) [Runnable] (c) [Running] (1) [start()] (2) [run()] (3) [yield()] (4) [wait()] (5) [notifyAll()] (6) [run() ends] The scheduler can cause transitions on edges [2 and 3]. Question 2 Correct Mark 20.00 out of 20.00 Flag question A programmer creates the following two Java classes: public class A { public synchronized void a1(){ //do something } public void a2(){ //do something } public synchronized int a3(){ int var = 0; //do something changing var return var; } } public class B { public void b1(){ //do something } public synchronized int b2(){ int var = 0; //do something changing var return var; } public void b3(){ //do something } } / Then a main method which does the following: public static void main(String[] args){ A firstA = new A(); A secondA = new A(); B firstB = newB(); //create some threads that perform operations on firstA, secondA and first B and start them } The precise details of the creation and function of the threads are not important, so they are not given, you may assume that they run in parallel and call methods on the created objects. Further you may assume that no other mechanisms that are not shown prevent methods from running concurrently. Which of the following groups of methods cannot be run concurrently (i.e. will be sequenced so that one nishes before the other starts) if called at the same time by two dierent threads? Select one or more: rstA.a1() and secondA.a3() secondA.a1() and rstB.b1() rstA.a2() and rstB.b3() secondA.a3() and secondA.a3() Synchronized methods in the same object cannot be run in parallel, and that includes with themselves, the keyword synchronized requires one to complete before the other starts. Two dierent threads can attempt to call the same method at once, think for example, of two producers calling produce at the same time rstB.b1() and rstB.b1() rstA.a3() and rstB.b2() secondA.a1() and secondA.a3() Synchronized methods in the same object cannot be run in parallel, the keyword synchronized requires one to complete before the other starts rstB.b1() and rstB.b2() rstB.b1() and rstB.b3() rstA.a1() and secondA.a2() rstA.a2() and secondA.a2() Select whether each of the following statements is true or false: It is sometimes more ecient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run . Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource . notify and wait can be called outside a monitor . In Java methods will only require the monitor lock if they are synchronized . The correct answers are: secondA.a1() and secondA.a3(), secondA.a3() and secondA.a3() Question 3 Correct Mark 10.00 out of 10.00 Flag question True True False True Congratulations! The correct answer is: / Question 4 Correct Mark 10.00 out of 10.00 Flag question This question is about Java programming using swing. Select whether each of the following statements is true or false: Calling repaint() from a method running in the main thread will cause the paint method to be executed in the event dispatch thread. . If programmers want to create a threaded GUI they must exlicitly create separate threads . Threading problems cannot occur when using swing because it is thread safe. . It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. . True False False False Congratulations! The correct answer is: This question is about Java programming using swing. Select whether each of the following statements is true or false: Calling repaint() from a method running in the main thread will cause the paint method to be executed in the event dispatch thread. [True]. If programmers want to create a threaded GUI they must exlicitly create separate threads [False]. Threading problems cannot occur when using swing because it is thread safe. [False]. It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. [False]. Question 5 Correct Mark 10.00 out of 10.00 Flag question Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. / Select whether each of the following statements is true or false: It is sometimes more ecient to use notify() rather than notifyAll() if threads that are unblocked are guaranteed to be able to run [True]. Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource [True]. notify and wait can be called outside a monitor [False]. In Java methods will only require the monitor lock if they are synchronized [True]. 1: public class CrossingUser extends Thread { 2: private String mode; 3: private Crossing crossing; 4: 5: public CrossingUser(Crossing toUse, String modeIn){ 6: mode = modeIn; 7: crossing = toUse; 8: } 9: 10: public void run(){ 11: crossing.enterCrossing(this); 12: crossing.useCrossing(this); 13: crossing.leaveCrossing(this); 14: } 15: 16: public int timeToCross(){ 17: if(mode.equals("ROAD")){ 18: 19: 20: 21: 22: 23: 24: 25: 26: } 27: } return 50; } else { return 200; } } public String getMode(){ return mode; 1: public class Crossing { 2: 3: private String mode = ""; 4: private int users = 0; 5: 6: enterCrossing(CrossingUser u){ 7: ( && !u.getMode().equals(mode) ){ 9: ; 8: try{ wait() 10: e){ 11: 13: 13: 14: 15: 16: Entering the Crossing"); 17: } 18: 19: useCrossing(CrossingUser u){ InterruptedException 20: 21: 22: 23: 24: 25: } 26: 27: try{ } catch ( e){ e.printStackTrace(); } public synchronized void } } catch ( e.printStackTrace(); } while mode = u.getMode() !mode.equals("") ++users; System.out.println(u.getMode() + " User ; public void Thread.sleep(u.timeToCross()) ; InterruptedException public synchronized void leaveCrossing(CrossingUser u){ 28: 29: --users; 30: if(users == 0){ 31: ; mode = "" 32: } 33: System.out.println(u.getMode() + " User Leaving the Crossing"); 34: ; 35: } 36: } notifyAll() Your answer is correct. The correct answer is: Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. / Question 6 Correct Mark 10.00 out of 10.00 Flag question Now the following rules are to be enforced: It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2); No more than 1 road user can be on the crossing at the same time (restriction 3). Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You're answer will not be marked as correct unless you complete the restrictions in the specied order (this is a limitiation of KEATS, of course any order of the conditions would work in Java). (( ) //restriction 1 () //restriction 2 while !u.getMode().equals(mode) && !mode.equals("") || users > 2
&&
u.getMode().equals(“FOOT”)
||
users > 0
&&
( )){
u.getMode().equals(“ROAD”)
//restriction 3
/
1: public class CrossingUser
extends Thread {
2: private String mode;
3: private Crossing crossing;
4:
5: public CrossingUser(Crossing
toUse, String modeIn){
6: mode = modeIn;
7: crossing = toUse;
8: }
9:
10: public void run(){
11:
crossing.enterCrossing(this);
12:
crossing.useCrossing(this);
13:
crossing.leaveCrossing(this);
14: }
15:
16: public int timeToCross(){
17:
18:
19:
20:
21:
22:
23:
24:
25:
26: }
27: }
if(mode.equals(“ROAD”)){
return 50;
} else {
return 200; }
}
public String getMode(){
return mode;
1: public class Crossing {
2:
3: private String mode = “”;
4: private int users = 0;
5:
6: [public synchronized void]
enterCrossing(CrossingUser u){
7: [while]([!mode.equals(“”) ] [&&]
[!u.getMode().equals(mode)]){
8:
9:
10:
11:
13:
13:
try{
[wait()];
} catch ([InterruptedException] e){
e.printStackTrace();
}
}
[mode = u.getMode()];
++users;
System.out.println(u.getMode() + ” User
14:
15:
16:
Entering the Crossing”);
17: }
18:
19:
20:
21:
22:
23:
24:
25: }
26:
[public void] useCrossing(CrossingUser u){
try{
[Thread.sleep(u.timeToCross())];
} catch ([InterruptedException] e){
e.printStackTrace();
}
27: [public synchronized void]
leaveCrossing(CrossingUser u){
28:
29: –users;
30: if(users == 0){
31: [mode = “”];
32: }
33: System.out.println(u.getMode() + ” User
Leaving the Crossing”);
34: [notifyAll()];
35: }
36: }

try {//etc. }
Your answer is correct.
The correct answer is:
Now the following rules are to be enforced:
It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2);
No more than 1 road user can be on the crossing at the same time (restriction 3).
Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You’re answer will not be marked as correct unless you complete the restrictions in the specied order (this is a limitiation of KEATS, of course any order of the conditions would work in Java).
[while](([!u.getMode().equals(mode)] [&&] [!mode.equals(“”) ] ) [||] //restriction 1
([users > 2] [&&] [u.getMode().equals(“FOOT”)]) [||] //restriction 2
([users > 0] [&&] [u.getMode().equals(“ROAD”)])){ //restriction 3
try {//etc. }
Question 7 Correct Mark 15.00 out of 15.00 Flag question
Consider the following method (and class variables), that are intended to enforce the following rules:
The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once;
Only one car can travel westbound at once.
int carCount = 0;
boolean westbound = false;
public synchronized void enterBridge(Vehicle v){
//block
westbound = v.getWestbound(); //set direction to your direction
++carCount; //increment cars using bridge
System.out.println(v + “ entering the bridge”);
}
Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of the code is correctly implemented.
block 1:
while((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 2:
while((v.getWestbound() != westbound && carCount > 0) &&
(!v.getWestbound() && carCount > 2) &&
/

(v.getWestbound() && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 3:
if((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 4:
if((v.getWestbound() != westbound && carCount > 0)) {
if (!v.getWestbound() && carCount > 2) {
if (v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
} }
}
block 5:
if((v.getWestbound() != westbound && carCount > 0)) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(!v.getWestbound() && carCount > 2) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 6:
while((v.getWestbound() != westbound && carCount > 0)) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
while(!v.getWestbound() && carCount > 2) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
/

while(v.getWestbound() && carCount > 0) {
try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
Select one or more:
a. block 1 b. block 2
c. block 3 d. block 4 e. block 5 f. block 6
Correct!
The correct answer is: block 1
Question 8 Partially correct Mark 10.00 out of 15.00 Flag question
Consider the following methods to exit and cross the bridge that are to be a part of the same class as the previous enterBridge method.
public synchronized void exitBridge(Vehicle v){
–carCount;
System.out.println(v + “ exiting the bridge”);
notifyAll();
}
public void crossBridge(){
try{
Thread.sleep(100);
} catch (InterruptedException e){
e.printStackTrace();
}
}
Select all statements that are correct:
Select one or more:
If the order of the println and notifyAll statements are swapped it is possible that another car will enter the bridge before the
message exiting the bridge is printed. Java operates a N > W=E policy, therefore the notifying process will get to continue and nish (maintaining the monitor lock) before the waiting processes can enter.
No threads will be needlessly blocked if notifyAll() is replaced with notify()
If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should. Correct! The threads would each have to wait in turn to execute crossBridge, and could therefore not be sleeping at the same
time.
Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock. Correct! No cars would be able to enter the bridge once three had entered because they would wait indentely for car count to be low enough.
Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one. Correct!
/

Week 5 Quiz – Assessed Coursework, Deadline 10:00am 25/02/2019
For each of the following scenarios use the Banker’s algorithm to determine whether the system is in a safe or an unsafe state. If the system is safe, give the safe order that Banker’s algorithm would produce for the processes (you should assume that ties are broken by selecting the process with the smallest number when multiple processes are able to run). If the system is not in a safe state, give the order processes that have executed were executed in, and ll the remaining boxes with X. All allocations and requirements are specied for three resources in the order R1, R2, R3.
Scenario 1:
P0 max requirement 0,7,4 and allocation 0,3,0. P1 max requirement 3,4,2 and allocation 0,0,0. P2 max requirement 0,4,4 and allocation 0,0,0. P3 max requirement 0,3,4 and allocation 0,1,1. P4 max requirement 4,1,3 and allocation 3,0,1.
The current resource availability is:1,3,2. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
Scenario 2:
P0 max requirement 1,1,0 and allocation 0,0,0. P1 max requirement 3,1,0 and allocation 1,0,0. P2 max requirement 2,0,0 and allocation 0,0,0. P3 max requirement 0,1,3 and allocation 0,0,0. P4 max requirement 7,0,3 and allocation 0,0,0.
The current resource availability is:6,1,3. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
Scenario 3:
P0 max requirement 4,3,4 and allocation 3,0,2. P1 max requirement 0,2,7 and allocation 0,0,3. P2 max requirement 3,0,7 and allocation 0,0,1. P3 max requirement 1,0,2 and allocation 0,0,0. P4 max requirement 0,4,1 and allocation 0,1,0.
The current resource availability is:1,3,1. The system is in a
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
Question 1 Partially correct Mark 2.22 out of 20.00 Flag question
Unsafe
P0
P2
Unsafe
P0
P2
Unsafe
/
The correct answers are: Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one., Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock., If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should.

P0
P2
Question 2 Partially correct Mark 5.00 out of 10.00 Flag question
Select whether each of the following statements is true or false:
The Resource allocation graph algorithm only works if there is a single instance of each resource . Deaclock can only occur if there a circular wait .
When using the Banker’s algorithm to do deadlock avoidance a process could be made to wait, even though running now it would not lead to deadlock .
Deadlock cannot occur in a system that has only one resource .
False
True
True
False
You have correctly selected 2.
The correct answer is:
Select whether each of the following statements is true or false:
The Resource allocation graph algorithm only works if there is a single instance of each resource [True].
Deaclock can only occur if there a circular wait [True].
When using the Banker’s algorithm to do deadlock avoidance a process could be made to wait, even though running now it would not lead to deadlock [True].
Deadlock cannot occur in a system that has only one resource [True].
Question 3 Partially correct Mark 5.00 out of 10.00 Flag question
Consider the following code:
public class myFirstThread extends Thread {
Semaphore s1,s2,s3;
public myFirstThread(Semaphore a,
Semaphore b,
s1 = a;
s2 = b;
s3 = c;
}
public void run(){
Semaphore c){
//first thread implementation
}
}
public class mySecondThread extends Thread
{
Semaphore s1,s2,s3;
public mySecondThread (Semaphore a,
Semaphore b,
s1 = a;
s2 = b;
s3 = c;
}
public void run(){
Semaphore c){
//second thread implementation
}
}
public static void main(String[] args){
}
Semaphore s1 = new Semaphore(1);
Semaphore s2 = new Semaphore(2);
Semaphore s3 = new Semaphore(1);
Thread t1 = new myFirstThread(s1,s2,s3);
Thread t2 = new mySecondThread(s1,s2,s3);
t1.start();
t2.start();
/

Which of the following pairs of implementations of the run methods can deadlock? Exception handling code (try, catch) has been omitted for clarity.
rst thread implementation
second thread implementation
a
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s2.release();
}
b
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s1.acquire();
s3.acquire();
s3.release();
s1.release();
}
c
public void run(){
s1.acquire();
s3.release();
}
public void run(){
s3.acquire();
s1.release();
}
d
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
public void run(){
s3.acquire();
s1.acquire();
s3.release();
s1.release();
}
e
public void run(){
s1.acquire();
s1.release();
}
public void run(){
s3.acquire();
s3.release();
}
f
public void run(){
s2.acquire();
s1.acquire();
s1.release();
s2.release();
}
public void run(){
s1.acquire();
s2.acquire();
s2.release();
s1.release();
}
g
public void run(){
s1.acquire();
s3.acquire();
s1.release();
s3.release();
}
public void run(){
s1.acquire();
s1.release();
}
Select one or more:
it.
a
b c d e
Correct! Since s1 is not signalled by t2 after being acquired it will become zero and both threads could end up waiting for What happens if t1 acquires s1 then t2 acquires s3?
Whilst the semaphores are not acquired in the same order, there are two units of s2 so both can hold that at the same
f
time, removing the possibility of t1 holding s2 and t2 being unable to proceed.
g
The correct answers are: a, b
Question 4 Partially correct Mark 1.67 out of 10.00 Flag question
/

public class Buffer {
ArrayList messages;
public Buffer(){
messages = new ArrayList();
messages.add(“Hello”);
messages.add(“World”);
}
public synchronized void
moveFirstItemTo(Buffer other){
if(!messages.isEmpty()){
other.addItem(messages.remove(0));
} }
public synchronized void addItem(String
message){
messages.add(message);
}
}
public class BufferUser extends Thread {
Buffer b1;
Buffer b2;
public BufferUser(Buffer firstBuffer,
Buffer secondBuffer){
b1 = firstBuffer;
b2 = secondBuffer;
}
public void run(){
while(true){
b1.moveFirstItemTo(b2);
}
} }
public static void main(String[] args) {
Buffer b1 = new Buffer();
Buffer b2 = new Buffer();
BufferUser t1 = new BufferUser(b1,b2);
BufferUser t2 = new BufferUser(b2,b1);
t1.start();
t2.start();
}
Select one or more:
a. This program is guaranteed to deadlock.
b. This program will almost certainly deadlock if ran for long enough.
c. This program is unlikely to deadlock in a short time period.
d. This program can never deadlock.
e. If the keyword synchronized was removed from the addItem method the program could not deadlock.
f. If the keyword synchronized was removed from the addItem method loss of data could occur.
Consider the following concurrent program:
The correct answers are: This program will almost certainly deadlock if ran for long enough., If the keyword synchronized was removed from the addItem method the program could not deadlock., If the keyword synchronized was removed from the addItem method loss of data could occur.
Question 5 Correct Mark 10.00 out of 10.00 Flag question
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false / Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 . p1,p2,p3,q1,q2,q3 . p1,p2,q1,q2,p3,q3 . p1,q1,p2,p3,q2,q3 . Leads to Deadlock Does not Necessarily Lead to Deadlock Leads to Deadlock Does not Necessarily Lead to Deadlock The correct answer is: Consider the following concurrent program: Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 [Leads to Deadlock]. p1,p2,p3,q1,q2,q3 [Does not Necessarily Lead to Deadlock]. p1,p2,q1,q2,p3,q3 [Leads to Deadlock]. p1,q1,p2,p3,q2,q3 [Does not Necessarily Lead to Deadlock]. boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Question 6 Incorrect Mark 0.00 out of 10.00 Flag question The number of possible interleavings of i threads (assuming all interleavings are valid) is given by the formula: (n1+n2 + ... + ni)!/(n1!*n2!*...*ni!)) where ni is the number of atomic instructions in thread i. Assuming each line of the following program represents an atomic instruction complete the following statement: There are possible interleavings of this program of which lead to deadlock. For each of the following scenarios use the Banker's algorithm to determine whether the system is deadlocked. If the system is deadlocked, give the processes involved in the deadlock; if not set all to X. All allocations and requests are specied for three resources in the order R1, R2, R3. Scenario 1: boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false 720 360 Question 7 Partially correct Mark 6.67 out of 20.00 Flag question P0 requested 0,0,1 and allocation 0,1,1. / P1 requested 2,1,1 and allocation 0,0,0. P2 requested 2,2,1 and allocation 1,0,0. P3 requested 1,1,0 and allocation 1,0,0. P4 requested 1,2,1 and allocation 0,1,0. The current resource availability is: 0,1,1. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Scenario 2: P0 requested 0,1,1 and allocation 1,1,0. P1 requested 0,1,2 and allocation 0,0,0. P2 requested 0,2,2 and allocation 0,0,0. P3 requested 0,0,1 and allocation 0,0,0. P4 requested 2,0,2 and allocation 0,0,0. The current resource availability is: 2,1,2. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Scenario 3: P0 requested 2,0,0 and allocation 0,0,0. P1 requested 1,0,0 and allocation 0,1,0. P2 requested 2,2,0 and allocation 0,1,1. P3 requested 2,0,1 and allocation 0,1,1. P4 requested 2,1,2 and allocation 0,0,0. The current resource availability is: 2,0,0. The system is . The following processes are deadlocked (enter X if the process is NOT deadlocked): Which of the following resource allocation graphs represent a deadlocked system? ab Deadlocked P0 X Deadlocked X X X P0 X X X X Deadlocked P0 Question 8 Incorrect Mark 0.00 out of 10.00 Flag question / cd Select one: All of them. None of them. b. c and d only. a, c and d only. a and b only. a, b and d only. b and d only. d only. c and d only Week 6 Quiz - Deadline 10:00 am on Tuesday 03/3/2020 Absolute code can be generated for : Select one: a. interrupt binding b. load-time binding c. compile-time binding d. excution-time binding ---------------------- is the method of binding instructions and data to memory performed by most general-purpose operating systems. Select one: a. Interrupt binding b. Compile time binding c. Load-time binding / The correct answer is: c and d only Question 1 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: compile-time binding Question 2 Incorrect Mark 0.00 out of 5.00 Flag question d. Execution time binding Your answer is incorrect. The correct answer is: Execution time binding Question 3 Correct Mark 5.00 out of 5.00 Flag question Suppose a program is operating with execution-time binding and the physical address generated is 300. The relocation register is set to 100. What is the corresponding logical address? Select one: a. 300 b. 199 c. 100 d. 200 The mapping of a logical address to a physical address is done in hardware by the ________. Select one: a. memory-management-unit (MMU) b. dynamic loading register c. relocation register d. memory address register _____ is the dynamic storage-allocation algorithm which results in the smallest leftover hole in memory. Select one: a. First t b. None of the options c. Worst t d. Best t Your answer is correct. The correct answer is: 200 Question 4 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: memory-management-unit (MMU) Question 5 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. / Question 6 Correct Mark 5.00 out of 5.00 Flag question The roll out, roll in variant of swapping is used ____. Select one: a. when a backing store is not necessary b. for the round-robin scheduling algorithm c. for priority-based scheduling algorithms d. when the load on the system has temporarily been reduced This question is about contiguous memory allocation, where memory is divided into used and unused blocks of memory, of varying sizes. Which of the following statements about contiguous memory allocation are true: Select one or more: a. Contiguous memory allocation suers from external fragmentation Correct! b. In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100. c. When using contiguous memory allocation for processes, compaction can be used to x external fragmentation d. Round-robin scheduling relies on contiguous memory allocation Round-robin scheduling is a process scheduling algorithm you met in the rst lecture. It doesn't mind either way whether contiguous memory allocation is used or not. Your answer is correct. The correct answer is: for priority-based scheduling algorithms Question 7 Partially correct Mark 0.42 out of 5.00 Flag question The correct answers are: Contiguous memory allocation suers from external fragmentation, In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100., When using contiguous memory allocation for processes, compaction can be used to x external fragmentation Question 8 Partially correct Mark 5.00 out of 10.00 Flag question Consider the following Java code: 1613: public class SomeCode { 1614: 1615: 1616: 1617: 1618: 1619: 1620: public static int v = 7; public static int w = 5; public static void a() { int t = 10; v=v +t; t=t *2; w=w +t; 1621: b(t); / The correct answer is: Best t 1622: 1623: 1624: 1625: 1626: 1627: 1628: 1629: 1630: 1631: System.out.println(v + w); } public static void b(int param) { int s=5; for (inti=0;i<3;++i){ s=s+param; } v= v+1; // What is on the stack here? } public static void main(String[] args) { int douglas = 40; douglas = douglas + 2; a(); 1632: 1633: 1634: 1635: 1636: 1637: 1638: } What is printed to the screen when this code executes? System.exit(0); } What values are on the stack when execution reaches line 1630? Start lling in these boxes at the right hand side -- i.e. the item on the bottom of the stack goes in the rightmost box. If there are more boxes than you need, then ll the spare left-hand boxes with 0. Note, you should enter the values of variables on the stack, not their names; and you don't need to include the 'args[]' passed to main(). 0 0 0 Question 9 Partially correct Mark 1.25 out of 5.00 Flag question 18 43 8 2 25 10 42 Which of the following statements about paged memory allocation are true? Select one or more: a. When using paging, logical addresses are split into a page number, and an oset b. Paging is based on diving memory into frames, the size of which are a power of two important.) c. Using paging can lead to external fragmentation between frames of allocated memory. reasons for using memory paging is to eliminate external fragmentation: free frames, on the free frames list, can be anywhere in memory, even between two frames that are in use. d. Every call to 'new' requests another frame of memory, to store the resulting object. For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate Correct! (The power of two bit is Not quite. One of the key The correct answers are: Paging is based on diving memory into frames, the size of which are a power of two, When using paging, logical addresses are split into a page number, and an oset Question 10 Partially correct Mark 3.33 out of 10.00 Flag question / { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? 216 216 216 Your answer is partially correct. You have correctly selected 1. The correct answer is: For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? [12] The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? [216] • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? [288] Question 11 Correct Mark 5.00 out of 5.00 Flag question Hierarchical page tables are appropriate for 64-bit architectures. Select one: a. TRUE / b. FALSE Your answer is correct. The correct answer is: FALSE Question 12 Correct Mark 5.00 out of 5.00 Flag question _____ is the dynamic storage-allocation algorithm which results in the largest leftover hole in memory. Select one: a. First t b. None of the above c. Best t d. Worst t Assume a system has a TLB hit ratio of 90%. It requires 15 nanoseconds to access the TLB, and 85 nanoseconds to access main memory. What is the eective memory access time in nanoseconds for this system? Select one: a. 22 b. 176.4 c. 108.5 d. 100 Consider a logical address with 18 bits used to represent an entry in a conventional page table. How many entries are in the conventional page table? Select one: a. 1024 Your answer is correct. The correct answer is: Worst t Question 13 Incorrect Mark 0.00 out of 5.00 Flag question Your answer is incorrect. The correct answer is: 108.5 Question 14 Correct Mark 5.00 out of 5.00 Flag question b. 262144 / c. 1048576 d. 18 Assume the value of the base and limit registers are 1200 and 350 respectively. Which of the following addresses is legal? Select one: a. 1200 b. all of the above c. 1551 d. 355 What is the context switch time, associated with swapping, if a disk drive with a transfer rate of 2 MB/s is used to swap out part of a program that is 200 KB in size? Assume that no seeks are necessary and that the average latency is 15 ms. The time should reect only the amount of time necessary to swap out the process. Select one: a. None of the options b. 120 ms c. 100 ms d. 113 ms What is the advantage of using dynamic loading? Select one: a. dynamic loading allows unused routines to stay out of main memory so that memory can be used more eectively b. dynamic loading allows the system to obtain better memory-space utilization c. All of the options are correct d. With dynamic loading a program does not have to be stored, in its entirety, in main memory Your answer is correct. The correct answer is: 262144 Question 15 Partially correct Mark 1.67 out of 5.00 Flag question Your answer is partially correct. The correct answer is: 1200 Question 16 Incorrect Mark 0.00 out of 5.00 Flag question Your answer is incorrect. The correct answer is: 113 ms Question 17 Correct Mark 5.00 out of 5.00 Flag question / Your answer is correct. The correct answer is: All of the options are correct Question 18 Correct Mark 5.00 out of 5.00 Flag question Hashed page tables are commonly used when handling addresses larger than 32 bits. Select one: a. FALSE b. TRUE This is the end of the quiz questions - submit your work when you are happy. Remember, once you have pressed submit, you cannot change your answers. Week 7 Coursework - KEATS Quiz, Deadline 10:00 am Tuesday 10/03/2020 A 32-bit computer has a virtual-memory space of 2^32 bytes. The computer is using memory paging, and the page size is 2^8 (i.e. 256) bytes. How many bits of the memory address are used for the page number? How many bits of the memory address are used for the oset? If each physical memory address is stored in 32-bits (i.e. 2^2 bytes), how large is the page table, in bytes? Give your answer as a power of two - e.g. if your answer is (2^10), then enter 10 into the box. Page table size = 2^ bytes. Consider a system with 3 frames of memory and the following sequence of page accesses: 0, 3, 0, 3, 1, 3, 0, 3, 0, 3, 2, 3, 2, 1, 2 When do page faults occur using the FIFO and LRU page replacement algorithms? Enter your answer as a string, comprising the letters Y and N, where Y means there was a page fault, and N means there was not. For instance, if you think there were three page faults to start with, and then no page faults after that, enter YYYNNNNNNNNNNNN Do not include any spaces or punctuation in your answer. Your answer is correct. The correct answer is: TRUE Information Flag question Question 1 Correct Mark 20.00 out of 20.00 Flag question 24 8 26 Question 2 Correct Mark 20.00 out of 20.00 Flag question / FIFO Page faults: LRU Page faults: Thrashing is bad, m'kay. But which of the following would the situation worse, better, or have no eect at all? YYNNYNNNNNYNNNN YYNNYNNNNNYNNYN Information Flag question Question 3 Correct Mark 5.00 out of 5.00 Flag question Adding a bigger hard drive will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing c. Have no eect on the amount of thrashing is the time taken to swap pages to/from disk. Correct - a bigger hard drive would have more free space, but the bottleneck The correct answer is: Have no eect on the amount of thrashing Question 4 Correct Mark 5.00 out of 5.00 Flag question Terminating some processes (closing some programs) will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we terminate some processes, then memory is freed up, reducing the amount of thrashing. c. Have no eect on the amount of thrashing Adding more memory to the machine will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - adding more memory increases how much memory each process can use, reducing the number of page faults, and hence reducing thrashing. c. Have no eect on the amount of thrashing The correct answer is: Reduce the amount of thrashing Question 5 Correct Mark 5.00 out of 5.00 Flag question The correct answer is: Reduce the amount of thrashing Question 6 Correct Mark 5.00 out of 5.00 Flag question Rewriting code to have a smaller working set (locality) will: / Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we can get the total working set size to be less than the amount of physical memory in the machine, we can hope to eliminate thrashing. c. Have no eect on the amount of thrashing In systems that support virtual memory, ____. Select one: a. virtual memory is separated from logical memory. b. virtual memory is separated from physical memory. c. physical memory is separated from secondary storage. d. physical memory is separated from logical memory. Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what is the number of page faults for the given reference string? Select one: 8 14 10 13 Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what will be the nal conguration of the three frames following the execution of the given reference string? Select one: a. 3, 4, 2 b. 4, 2, 3 c. 3, 1, 4 d. 4, 1, 3 / The correct answer is: Reduce the amount of thrashing Question 7 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: physical memory is separated from logical memory. Question 8 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: 8 Question 9 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: 3, 4, 2 Question 10 Correct Mark 5.00 out of 5.00 Flag question Belady's anomaly states that ____. Select one: a. for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases b. as the number of allocated frames increases, the page-fault rate may decrease for all page replacement algorithms c. giving more memory to a process will improve its performance d. for some page replacement algorithms, the page-fault rate may decrease as the number of allocated frames increases Your answer is correct. The correct answer is: for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases Question 11 Correct Mark 5.00 out of 5.00 Flag question Optimal page replacement ____. Select one: is the page-replacement algorithm most often implemented requires that the system keep track of previously used pages is used mostly for comparison with other page-replacement schemes can suer from Belady's anomaly _____ is the algorithm implemented on most systems. Select one: LRU Most frequently used FIFO Least frequently used Your answer is correct. The correct answer is: is used mostly for comparison with other page-replacement schemes Question 12 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: LRU / Week 8 Coursework - Deadline: 10:00, 20th of March 2020 Question 1 Correct Mark 5.00 out of 5.00 Flag question Which of the following two statements are security problems that can arise and need to be protected against when users simultaneously share a computing system -- i.e. they would not otherwise be an issue on a single-user system Select one or more: a. One user's process might access the memory of another user's process Yes, in principle, if one user's process accessed the memory of another user's process, it could, for instance, look at what document they were currently editing. b. Users can accidentally delete their les from disk c. Condential les kept on disk could be accessed by any user It's important to use access control to ensure users can have private les that only they (and systems administrators) can access. d. The system might start to run unacceptably slowly An advantage of compiler-based enforcement of access control is privileges are closely related to the concept of a data type. The correct answers are: One user's process might access the memory of another user's process, Condential les kept on disk could be accessed by any user Question 2 Correct Mark 5.00 out of 5.00 Flag question access linguistic Your answer is correct. The correct answer is: An advantage of compiler-based enforcement of access control is[access] privileges are closely related to the [linguistic ] concept of a data type. Question 3 Correct Mark 5.00 out of 5.00 Flag question The The for both the and association between processes and domains. users normally decide the contents of the access-matrix entries. Your answer is correct. The correct answer is: The [users] normally decide the contents of the access-matrix entries. Question 4 Partially correct Mark 3.75 out of 5.00 Flag question access matrix provides an appropriate mechanism for defining and implementing variable control static dynamic Your answer is partially correct. / Question 5 Partially correct Mark 2.50 out of 5.00 Flag question it is difficult to take advantage of special groupings of objects or domains when implementing using a comiler-based enforcement global table Your answer is partially correct. You have correctly selected 1. The correct answer is: it is difficult to take advantage of special groupings of objects or domains when implementing [access matrix] using a [global table] Question 6 Incorrect Mark 0.00 out of 5.00 Flag question Process P should be able to switch from domain Di to domain Dj if and only if the ∈ access(i, j). transfer right transfer right Your answer is incorrect. The correct answer is: Process P should be able to switch from domain Di to domain Dj if and only if the [access right] [switch ] ∈ access(i, j). Question 7 Correct Mark 4.00 out of 4.00 Flag question The rights allow a process to change the entries in a column in the access matrix and the copy and owner control rights applicable to objects only. domain Your answer is correct. The correct answer is: The [copy and owner] rights allow a process to change the entries in a column in the access matrix and the [control ] rights applicable to [domain] objects only. Question 8 Partially correct Mark 4.00 out of 5.00 Flag question The by list is a object maintained by and accessed only . capability shell operating system users indirectly You have correctly selected 3. The correct answer is: The [access matrix] provides an appropriate mechanism for defining and implementing [strict control] for both the [static] and [dynamic] association between processes and domains. Your answer is partially correct. You have correctly selected 4. The correct answer is: The [capability] list is a [protected ]object maintained by [operating system ]and accessed by [users] only [indirectly]. / Question 9 Correct Mark 5.00 out of 5.00 Flag question Most systems use a combination of . When a process rst tries to access an object, the is searched. If access is denied, an exception condition occurs. Otherwise, a is created and attached to the process. access list and capabilities access list capability Your answer is correct. The correct answer is: Most systems use a combination of [access list and capabilities ] . When a process rst tries to access an object, the [access list ] is searched. If access is denied, an exception condition occurs. Otherwise, a [capability ] is created and attached to the process. Question 10 Partially correct Mark 1.50 out of 3.00 Flag question Enforcement by enforcement by the is than kernel more eective In , when a class is domain that gives the , the of that class. assigns the class to a programming languages for user-dened policy Your answer is partially correct. You have correctly selected 2. The correct answer is: Enforcement by [kernel ] is [less] [exible] than enforcement by the [programming languages ] for user-dened policy Question 11 Partially correct Mark 1.80 out of 3.00 Flag question Java initiated JVM security permissions Your answer is partially correct. You have correctly selected 3. The correct answer is: In [Java], when a class is [loaded], the [JVM] assigns the class to a [protection ] domain that gives the [permissions ] of that class. Question 12 Partially correct Mark 2.50 out of 5.00 Flag question A problem is the problem of that no can migrate outside of its execution environment. initially held in an connement guaranteeing object class / Your answer is partially correct. You have correctly selected 2. The correct answer is: A[connement] problem is the problem of [ guaranteeing] that no [information] initially held in an [object] can migrate outside of its execution environment. Question 13 Correct Mark 5.00 out of 5.00 Flag question The principle of least means that programs, users, and even systems be given privileges to perform their . privileges Your answer is correct. The correct answer is: The principle of least [privileges] means that programs, users, and even systems be given [just enough] privileges to perform their [tasks]. just enough tasks Question 14 Correct Mark 5.00 out of 5.00 Flag question Windows 2000 has a complex protection scheme at its core and yet has many security holes. Your answer is correct. The correct answer is: [Windows 2000] has a complex protection scheme at its core and yet has many security holes. Question 15 Incorrect Mark 0.00 out of 5.00 Flag question The principle, is useful in limiting the amount of damage a faulty process can cause in the system. least-privilged Your answer is incorrect. The correct answer is: The [need‐to‐know] principle, is useful in limiting the amount of damage a faulty process can cause in the system. Question 16 Partially correct Mark 2.50 out of 5.00 Flag question The association between a and a may be either or . process domain dynamic static / Your answer is partially correct. You have correctly selected 2. The correct answer is: The association between a [process] and a [domain]may be either [static ] or [dynamic]. Question 17 Correct Mark 5.00 out of 5.00 Flag question In the system, the protection domains are organized hierarchically into a . MULTICS Your answer is correct. The correct answer is: In the [MULTICS] system, the protection domains are organized hierarchically into a [ring structure]. Which of the following statements is not TRUE about Compiler Based Enforcement? Select one: Protection needs are declared, rather than programmed. The means for enforcement need to be provided by the designer of a subsystem. Protection requirements can be dened independently of any particular operating system facilities. Protection is embedded in linguistic concept of data type. Stack inspection is : Select one: Protection mechanism provided in Java programming language Useful for inspecting classes from un trusted sources Providing methods to request access to a protected resource either directly or indirectly All the options are correct Consider the following le-access-control situations. For each, choose whether it could be encoded using the standard UNIX owner/group/other permissions model - and if so, choose appropriate users, groups and permissions ring structure Question 18 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: The means for enforcement need to be provided by the designer of a subsystem. Question 19 Correct Mark 5.00 out of 5.00 Flag question Your answer is correct. The correct answer is: All the options are correct Question 20 Partially correct Mark 3.53 out of 10.00 Flag question / If you do not think the permissions can be written in owner/group/other format, choose 'No' then pick the 'It cannot be done' option for the other answers to that question. a) Harry creates a le. He wants to give read/write access to Ron and Hermione, and no access to anyone else. Can this be done using the owner/group/other model? If so: Who would be the owner of the le? Who would be in the group for the le? Ron: Hermione: What would their permissions be? What would the 'other' permissions be? b) Voldemort creates a le. He wants to give Snape read/write access, Bellatrix read-only access, and no access to anyone else. Can this be done using the owner/group/other model? If so: Who would be the owner of the le? Who would be in the group for the le? Snape: Bellatrix: What would their permissions be? What would the 'other' permissions be? c) Filch creates a le. He wants to give sta read/write access, and other users (e.g. pupils) read-only access. Can this be done using the owner/group/other model? If so: Who would be the owner of the le? Who would be the group for the le? What would their permissions be? What would the 'other' permissions be? Yes Harry Yes Yes r-- r-- Yes Voldemort Yes Yes r-- r-- No Filch Filch r-- r-- Week 10 Coursework - Deadline is extended to 10:00, 3'rd of April / Question 1 Partially correct Mark 7.50 out of 10.00 Flag question Select the Missing words: In Linux, are implemented within the by a creates a new process within the same virtual address space as the mechanism that process. threads kernel child parent Your answer is partially correct. You have correctly selected 3. The correct answer is: Select the Missing words: In Linux, [threads] are implemented within the [kernel] by a [clone] mechanism that creates a new process within the same virtual address space as the [parent ] process. Question 2 Incorrect Mark 0.00 out of 10.00 Flag question Which of the following statements is TRUE about Linux Threads? Select one: Fork creates a new process with its own identity, but that is allowed to share the data structures of its parent Linux uses the same internal representation for processes and threads A thread is a new process that has its own address space All of the three options Which of the following statements is TRUE about Linux schedular? Select one: All of the options Processes are assigned priorities that are based on the nice value only. The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. Processes with shorter sleep times are often CPU-bound and thus will have higher priorities. Your answer is incorrect. The correct answer is: Linux uses the same internal representation for processes and threads Question 3 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: a real-time range from0 to 99 and a nice value ranging from 100 to 140. / Question 4 Correct Mark 10.00 out of 10.00 Flag question Which of the following statements is TRUE about Linux virtual manager? Select one: The VM manager creates a new virtual address space when there is a exec system call All of the options The VM manager maintains logical and physical views of a process’s address space The VM manager creates a new virtual address space when there is a fork system call Which of the following is TRUE about keeping functionality in shared libraries rather than in the kernel itself? Select one: Manageability Reliability Performance All of the options Your answer is correct. The correct answer is: All of the options Question 5 Correct Mark 10.00 out of 10.00 Flag question Your answer is correct. The correct answer is: All of the options Question 6 Correct Mark 10.00 out of 10.00 Flag question The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with access to the the resources of the computer. Its code and data structures are kept in the space. address full all physical same single Your answer is correct. The correct answer is: The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with [full] access to the [all] the [physical ] resources of the computer. Its code and data structures are kept in the [same] [single ] address space. / Which of the following sentences is TRUE about writing an operating system using high-level programming languages ? Select one: All of the options The number of programming errors is reduced as the code becomes more compact High-level languages may provide advanced features such as bounds checking that further minimize programming errors and security loopholes. High-level programming languages have powerful programming environments that include tools such as debuggers and performance prolers that could be handy for developing code. Fill in the missing words: In Linux, a is a command that allows users to type commands from the keyboard to interact with the operating system . It is a computer program that the commands the user types and sends them to the operating system. Furthermore, it provides a environment consisting of environment . Your answer is correct. The correct answer is: All of the options Question 8 Correct Mark 10.00 out of 10.00 Flag question Shell interpreter kernel interprets programming variables Your answer is correct. The correct answer is: Fill in the missing words: In Linux, a [Shell] is a command [interpreter ] that allows users to type commands from the keyboard to interact with the operating system [kernel]. It is a computer program that [interprets ] the commands the user types and sends them to the operating system. Furthermore, it provides a [programming ] environment consisting of environment [variables ]. Question 9 Partially correct Mark 7.50 out of 10.00 Flag question UNIX process management separates the creation of distinct operations. system call system call to . and the running of a new program into two a new process and a new program is run after a threads fork creates execve Question 7 Correct Mark 10.00 out of 10.00 Flag question Your answer is partially correct. You have correctly selected 3. The correct answer is: / / Question 10 Correct Mark 10.00 out of 10.00 Flag question Which of the following statements is TRUE about The Linux source code is freely and widely available over the Internet and from CD-ROM vendors? Select one: Open source code implies both that security weaknesses can be found and xed faster by the Linux community, increasing the security of the system; and that attackers can more easily nd any weaknesses that do remain in Linux. All of the options Attackers’ jobs are made easier if they have access to the source code of the system they are trying to penetrate Linux’s source code is open to scrutiny by both the good guys and the bad guys. Your answer is correct. The correct answer is: All of the options UNIX process management separates the creation of [processes] and the running of a new program into two distinct operations. [fork] system call [creates ] a new process and a new program is run after a system call to [execve] . Quiz -1 Assessed Coursework, Deadline 10:00am Tuesday 28/01/2020 Mark 10.00 out of Question 1 Correct 10.00 Flag question Select whether each of the following statements is true or false: Aprocesscanmovedirectlyfromawaitingtoaterminatedstate False Globalvariablesarestoredinthestackofaprocess False Theprocesscontrolblockispartoftheprocessstoredinmemory False If a process requests I/O it moves from a running state to a waiting state True Aninterruptcausesaprocesstogofromarunningtoareadystate True The correct answer is: Select whether each of the following statements is true or false: A process can move directly from a waiting to a terminated state [False] Global variables are stored in the stack of a process [False] The process control block is part of the process stored in memory [False] If a process requests I/O it moves from a running state to a waiting state [True] An interrupt causes a process to go from a running to a ready state [True] Mark 10.00 out of Question 2 Correct 10.00 Flag question Schedule the following processes using first come first served scheduling: P0 duration: 1 arrives: 4 priority: 4 P1 duration: 5 arrives: 0 priority: 0 P2 duration: 8 arrives: 8 priority: 8 P3 duration: 3 arrives: 5 priority: 5 P4 duration: 3 arrives: 12 priority: 12 What is the average waiting time? Answer: 1.6 Correct! Well Done, you won't need the hints below. Hint: each process runs until it finishes, processes start in the order they arrived, see the lecture notes for more details The correct answer is: 1.6 Mark 10.00 out of Question 3 Correct 10.00 Flag question In scheduling a the scheduler cannot choose to stop a running process if another process arrives. When using migration in multiprocessing idle processors take jobs from the queues of busy processors. P1 (duration 17) P2 (duration 9) P3 (duration 19) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order . When using migration in multiprocessing idle processors take jobs from the queues of busy processors. Correct, well done! The correct answer is: In [non-pre-emptive] scheduling a the scheduler cannot choose to stop a running process if another process arrives. When using [pull] migration in multiprocessing idle processors take jobs from the queues of busy processors. P1 (duration 17) P2 (duration 9) P3 (duration 19) are scheduled using FCFS scheduling, the shortest average waiting time will be achieved if the processes arrive in the order [P2] [P1] [P3]. When using [pull] migration in multiprocessing idle processors take jobs from the queues of busy processors. Mark 14.57 out of Question 4 Partially correct 15.00 Flag question Schedule the following processes using pre-emptive priority scheduling: P0 duration: 3 arrives: 9 priority: 1 P1 duration: 4 arrives: 3 priority: 4 P2 duration: 9 arrives: 11 priority: 12 P3 duration: 10 arrives: 0 priority: 13 P4 duration: 14 arrives: 9 priority: 3 Fill in the schedule below: Process P3 P1 P3 P0 P4 P2 P3 Start Time Runs For 03 34 72 93 12 14 26 9 35 5 Now complete the waiting and turnaround times for each process, then the total and averages. Process Waiting Time P0 0 P1 0 P2 15 P3 30 P4 3 Total 48 Average 4.6 Turnaround Time 3 4 24 40 17 88 17.6 The correct schedule is: 0: P3 (3) 3: P1 (4) 7: P3 (2) 9: P0 (3) 12: P4 (14) 26: P2 (9) 35: P3 (5) Waiting times: P0 0 P1 0 P2 15 P3 30 P4 3 Turnaround times : P1 4 P3 40 P4 17 P0 3 P2 24 Mark 15.00 out of Question 5 Correct 15.00 Flag question This question is about multi-queue scheduling. Select all the true statements from the list below: Select one or more: In multi-queue scheduling all queues must have the same scheduling algorithm. In Multi-level feedback queue scheduling jobs always stay on the same queue. Multi-queue scheduling can be used on single processor systems. Correct! Multi-level feedback queues can be used for priority scheduling. Correct! Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling Correct! Another option is for higher priority queues to have absolute priority, using aging to prevent starvation. Correct! Well done. The correct answers are: Time slicing can be used to allow sharing of resources between queues in multi-level queue scheduling, Multi-queue scheduling can be used on single processor systems., Multi-level feedback queues can be used for priority scheduling. Information Flag question Information for answering Round Robin Scheduling Questions. If you have a quantum of 3 for example, and a schedule like this: 0: P0 (3) 3: P0 (3) 6: P1 (3) 9: P2 (3) 12: P2 (1) Then don't enter it as above, with the original quanta, but rather include the total time each process is running, so: 0: P0 (6) 6: P1 (3) 9: P2 (4) In your question there wouldn't be enough boxes to do it the first way round. Mark 8.30 out of Question 6 Partially correct 15.00 Flag question Schedule the following processes using round robin scheduling with quantum 3: P0 duration: 13 arrives: 0 P1 duration: 6 arrives: 7 P2 duration: 7 arrives: 5 P3 duration: 14 arrives: 14 P4 duration: 5 arrives: 4 Fill in the schedule below: Process P0 P2 P4 P0 Start Time 06 63 93 12 3 Runs For The correct schedule is: 0: P0 (6) 6: P4 (3) 9: P2 (3) 12: P0 (3) 15: P1 (3) 18: P4 (2) 20: P2 (3) 23: P3 (3) 26: P0 (3) 29: P1 (3) 32: P2 (1) 33: P3 (3) 36: P0 (1) 37: P3 (8) Waiting times: P0 24 P1 19 P2 21 P3 17 P4 11 Turnaround times : P3 31 P0 37 P2 28 P1 25 P4 16 Mark 10.00 out of Question 7 Correct 10.00 Flag question 15 3 P1 18 21 3 24 2 26 3 29 3 32 3 35 1 36 1 37 8 3 P2 P4 P0 P3 P1 P2 P0 P3 Now complete the waiting and turnaround times for each process, then the total and averages. Process Waiting Time P0 24 P1 22 P2 24 P3 17 P4 17 Total 104 Average 20.8 Turnaround Time 37 28 31 31 22 149 29.5 P3 Select whether each of the following statements is true or false: Congratulations! The correct answer is: Select whether each of the following statements is true or false: The ProcessBuilder class allows Java programs to create child processes [True]. In all operating systems a child process is killed if its parent is killed [False]. A child process always shares the resources of its parent [False]. The short term (CPU) scheduler decides which processes to load into memory [False]. Mark 15.00 out of Question 8 Correct 15.00 Flag question Schedule the following processes using shortest remaining time first scheduling: P0 duration: 6 arrives: 0 P1 duration: 18 arrives: 13 P2 duration: 3 arrives: 32 P3 duration: 17 arrives: 22 P4 duration: 12 arrives: 3 Fill in the schedule below: Process P0 P4 P1 P2 P1 P3 Start Time 06 6 12 18 14 32 3 35 4 39 17 Runs For Now complete the waiting and turnaround times for each process, then the total and averages. Process Waiting Time P0 0 P1 8 P2 0 P3 17 P4 3 Total 28 Average 5.6 Turnaround Time 6 26 3 34 15 84 16.8 The correct schedule is: TheProcessBuilderclassallowsJavaprogramstocreatechildprocesses True In all operating systems a child process is killed if its parent is killed False . . . . Achildprocessalwayssharestheresourcesofitsparent False Theshortterm(CPU)schedulerdecideswhichprocessestoloadintomemory False 0: P0 (6) 6: P4 (12) 18: P1 (14) 32: P2 (3) 35: P1 (4) 39: P3 (17) Waiting times: P0 0 P1 8 P2 0 P3 17 P4 3 Turnaround times : P4 15 P3 34 P1 26 P0 6 P2 3 Week 2 Quiz - Assessed Coursework, Deadline 10:00am 04/02/2020 Mark 10.00 out of Question 1 Correct 10.00 Flag question Select whether each of the following statements is true or false: JavaautomaticallycreatesaseparatethreadforaGUItomakesureitremainsresponsive True . Ifathreadcallsyield()itmovesfromarunningtoablockedstate False A line of Java code usually represents multiple atomic CPU instructions True The only way to create a class that will run as a thread in Java is to extend Thread . . False . Congratulations! The correct answer is: Select whether each of the following statements is true or false: Java automatically creates a separate thread for a GUI to make sure it remains responsive [True]. If a thread calls yield() it moves from a running to a blocked state [False]. A line of Java code usually represents multiple atomic CPU instructions [True]. The only way to create a class that will run as a thread in Java is to extend Thread [False]. Mark 20.00 out of Question 2 Correct 20.00 Flag question A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread q = new Printer("Q"); Thread p = new Printer("P"); q.start(); p.start(); try{ q.join(); } catch (Exception e){ e.printStackTrace(); } for(int i = 0; i < 10; ++i){ System.out.print(“R”); } } } The code for the class Printer is correctly implemented, the class extends Thread and the run method prints out the letter given as an argument to the constructor 10 times (it may, or may not, do other computation that does not produce any output). Which of the following are possible outputs of this program? (to save laborious counting you can safely assume that all answers contain 10Ps, 10Qs and 10Rs). 0: QQQQQQQQQQRRRRRRRRRRPPPPPPPPPP 1: PQPQPQPQPQPQPQPQPQPQRRRRRRRRRR The correct answer is: 6, 0, 1 and 5 only Mark 7.50 out of Question 3 Partially correct 10.00 Flag question Select whether each of the following statements is true or false: Ifeachindividualstatementinaconcurrentprogramisatomicthenthereisnocriticalsectionproblem. True . Threads can be used to make graphical interfaces responsive. True . Concurrnetprogramsareeasiertodebug. False . There is no point in writing threaded code for a machine with only 1 CPU. False . You have correctly selected 3. The correct answer is: Select whether each of the following statements is true or false: If each individual statement in a concurrent program is atomic then there is no critical section problem. [False]. Threads can be used to make graphical interfaces responsive. [True]. Concurrnet programs are easier to debug. [False]. There is no point in writing threaded code for a machine with only 1 CPU. [False]. Mark 11.25 out of Question 4 Partially correct 15.00 Flag question 2: PQRPQRPQRPQRPQRPQRPQRPQRPQRPQR 3: QRQRQRQRQRQRQRQRQRQRPPPPPPPPPP 4: PRPRPRPRPRPRPRPRPRPRQQQQQQQQQQ 5: PPPQQQPPQQPQQPPQPQQRRPRRRRRRRR 6: PPPPPPPPPPQQQQQQQQQQRRRRRRRRRR 7: PPPPPPPPPPRRRRRRRRRRQQQQQQQQQQ 8: PPPQQQPPQQPQQPPQPQPRQRRRRRRRRR 9: RRRRRRRRRRQQQQQQQQQQPPPPPPPPPP Select one: All of the above 6, 7 and 4 only 6 and 1 only 6 only 6, 0, 1, 8 and 5 only 6, 0, 1 and 5 only 6, 7, 1 and 8 only None of the above. Correct! Since q.join() is called the main thread must wait for q to finish before continuing. In the following solution to the critical section problem (note that the two processes are slightly different): Executionofthefollowinginterleaving:p0,q0,q1,p1,p2,q2wouldleadto violationofmutualexclusion . Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to starvation of q . boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false This program satisfies the requirement for . It is that p can never starve. Freedom From Deadlock False The correct answer is: In the following solution to the critical section problem (note that the two processes are slightly different): Execution of the following interleaving: p0,q0,q1,p1,p2,q2 would lead to [violation of mutual exclusion]. Continued execution of the following interleaving: p0,p1,q0,q1,p2,p3,p4,p0,p1,q1 would lead to [starvation of q]. This program satisfies the requirement for [Freedom From Deadlock]. It is [True] that p can never starve. Mark 10.00 out of Question 5 Correct 10.00 Flag question boolean wantp <- false, wantq <- false p q loop_forever p0: non-critical section p1: wantp <- true p2: await wantq = false p3: critical section p4: wantp <- false loop_forever q0: non-critical section q1: await wantp = false q2: wantq <- true q3: critical section q4: wantq <- false To verify that a solution to the critical section problem is correct we must show that the condition. When reasoning with concurrent programs we assume that no process will terminate in its section. If no process is able to enter its critical section this is called . Correct, well done! The correct answer is: To verify that a solution to the critical section problem is correct we must show that [all interleavings satisfy] the condition. When reasoning with concurrent programs we assume that no process will terminate in its [critical] section. If no process is able to enter its critical section this is called [deadlock]. Mark 6.67 out of Question 6 Partially correct 20.00 Flag question Consider the following solution to the critical section problem: boolean wantp <- false, wantq <- false p q loop_forever p1: non-critical section p2: P3: p4: P5: p6: p7: wantp <- true while wantq wantp <- false wantp <- true critical section wantp <- false loop_forever q1: non-critical section q2: q3: q4: q5: q6: q7: wantq <- true while wantp wantq <- false wantq <- true critical section wantq <- false Which of the three properties does this solution satisfy? Select one: Mutual Exclusion and Freedom From Deadlock only. Freedom From Starvation Only. Freedom From Deadlock Only. None. All Three: Mutual Exclusion, Freedom From Starvation, Freedom From Deadlock. Mutual Exclusion and Freedom From Starvation only. The correct answer is: Mutual Exclusion and Freedom From Deadlock only. Mark 15.00 out of Question 7 Correct 15.00 Flag question A programmer wrote the following code with the intention of creating a concurrent threaded program. public class myMain { public static void main(String[] args){ Thread p = new Printer("p"); Thread q = new Printer("Q"); p.run(); q.run(); for(int i = 0; i < 10; ++i){ System.out.println("R"); } } } What is the maximum number of threads belonging to this program running at any one time during its execution? Select one: 0 2 3 . 1 Correct! Although the programmer tried to start to threads they called run() instead of start(). This error meant that no new threads were created Further exercise: if the programmer had called start() how many processes would be running? The correct answer is: 1 Week 3 Quiz - Assessed Coursework, Deadline 10:00 am 11/02/2020 Mark 10.00 out of Question 1 Correct 10.00 Flag question Select whether each of the following statements is true or false: Ticketnumbersinthebakeryalgorithmareunbounded. True . Thebakeryalgorithmisefficientforuseinpractice. False . Setting number[i] to zero after the critical section in the bakery algorithm is important for success in the absence of contention. True . If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twicewhilstphastowait. False . Congratulations! The correct answer is: Select whether each of the following statements is true or false: Ticket numbers in the bakery algorithm are unbounded. [True]. The bakery algorithm is efficient for use in practice. [False]. Setting number[i] to zero after the critical section in the bakery algorithm is important for success in the absence of contention. [True]. If a process p has chosen a ticket number in the bakery algorithm and is in the waiting loop then another process could execute its critical section twice whilst p has to wait. [False]. Freedom From Deadlock and Freedom From Starvation only. Mutual Exclusion Only. At least one more property is satisfied. Mark 10.00 out of Question 2 Correct 10.00 Flag question Which of the following are valid outputs for the following program: Semaphore S1<- 0, S2 <- 0 p q r p1: print(“p”) p2: signal(S1) p3: signal(S2) q1: wait(S1) q2: print(“q”) r1: wait(S2) r2: print(“r”) Select one or more: rqp qpr rpq qrp pqr Correct! And there's at least one more. prq Good, that was the hard one, the scheduler might permit p1,p2,p3 and then schedule r. The correct answers are: pqr, prq Mark 20.00 out of Question 3 Correct 20.00 Flag question Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Solution1: MutualExclusionOnly Solution2: MutualExclusionOnly Solution3: FreedomFromDeadlockOnly Solution4: Both Solution5: Both Solution6: Both Solution 7: FreedomFrom Deadlock Only The correct answer is: Consider the following proposed pseudocode solutions to the critical section problem using semaphores. For each of the following (independent) solutions state whether they satisfy the requirements of mutual exclusion and/or freedom from deadlock for n identical threads each running as described in the solution. You may assume that a process will not terminate in its critical section or in its non-critical section for the purposes of this question. Solution 1 Solution 2 Solution 3 Solution 4 Semaphore S <- 0 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 non-critical section wait(S) critical section Semaphore S <- 1 non-critical section wait(S) signal(S) critical section Semaphore S <- 1 non-critical section wait(S) critical section signal(S) Solution 5 Solution 6 Solution 7 Solution 8 Semaphore S1 <- 1 Semaphore S2 <- 1 non-critical section wait(S1) wait(S2) critical section signal(S2) signal(S1) Semaphore S <- 1 wait(S) non-critical section critical section signal(S) Semaphore S <- 2 non-critical section wait(S) critical section signal(S) Semaphore S <- 1 wait(S) non-critical section signal(S) critical section Solution 1: [Mutual Exclusion Only] Solution 2: [Mutual Exclusion Only] Solution 3: [FreedomFrom Deadlock Only] Solution 4: [Both] Solution 5: [Both] Solution 6: [Both] Solution 7: [FreedomFrom Deadlock Only] Solution 8: [FreedomFrom Deadlock Only] Mark 20.00 out of Question 4 Correct 20.00 Flag question Solution8: FreedomFromDeadlockOnly Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends Thread { staticSemaphore safeToCross= newSemaphore(2) ; private String name; public Pedestrian(String nameIn){ name = nameIn; } public void run() { for(int i = 0; i < 3; ++i){ try{ Your answer is correct. The correct answer is: Complete the following java program using Semaphores. The program simulates pedestrians crossing a weak bridge. If more than 2 pedestrians cross the bridge at once then the bridge will collapse, your code must prevent this. When the pedestrians run they should do so as concurrent threads and should cross the bridge 3 times, the pedestrian should occupy the bridge for 100ms before leaving. import java.util.concurrent.Semaphore; public class Pedestrian extends [Thread] { [static Semaphore] safeToCross = [new Semaphore(2)]; private String name; public Pedestrian(String nameIn){ name = nameIn; } [public void run()]{ for(int i = 0; i < 3; ++i){ try{ [safeToCross.acquire();] System.out.println("Pedestrian " + name + " Entering the Bridge"); [Thread.sleep(100);] System.out.println("Pedestrian " + name + " Leaving the Bridge"); [safeToCross.release();] } catch ([InterruptedException] e){ e.printStackTrace(); } } System.out.println("Pedestrian " + name + " Entering the Bridge"); Thread.sleep(100); System.out.println("Pedestrian " + name + " Leaving the Bridge"); safeToCross.release(); } catch ( InterruptedException e.printStackTrace(); } } } e){ public static void main(String[] args){ Pedestrian dave = new Pedestrian("Dave"); dave. start() ; Pedestrian pete = new Pedestrian("Pete"); pete. start() ; Pedestrian jackie = new Pedestrian("Jackie"); jackie. start() ; Pedestrian jane = new Pedestrian("Jane"); jane. start() ; } } safeToCross.acquire(); } public static void main(String[] args){ Pedestrian dave = dave.[start()]; Pedestrian pete = pete.[start()]; Pedestrian jackie jackie.[start()]; Pedestrian jane = jane.[start()]; } } new Pedestrian("Dave"); new Pedestrian("Pete"); = new Pedestrian("Jackie"); new Pedestrian("Jane"); Mark 10.00 out of Question 5 Correct 10.00 Flag question Select whether each of the following statements is true or false: If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. True . Semaphoresareimplementedinhardware. False . Waitincreasesthevalueofthesemaphore'sintegervariable. False . Testandsetisprovidedbysoftware. False . Congratulations! The correct answer is: Select whether each of the following statements is true or false: If wait and signal are not executed atomically mutual exclusion can be violated in an otherwise correct semaphore solution to the critical section problem. [True]. Semaphores are implemented in hardware. [False]. Wait increases the value of the semaphore's integer variable. [False]. Test and set is provided by software. [False]. Mark 5.00 out of Question 6 Correct 5.00 Flag question Which of the three types of semaphore can be used to implement a solution to the critical section problem without the risk of starvation? Select one: Busy Wait Semaphores and Blocked Set Semaphores. Blocked Queue and Blocked Set semaphores only. Busy Wait Semaphores and Blocked Queue Semaphores. All of them. Blocked Queue semaphores only. Correct! Busy Wait sempahores only. None of them. Blocked Set semaphores only. The correct answer is: Blocked Queue semaphores only. Mark 15.00 out of Question 7 Correct 15.00 Flag question The correct answer is: A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain specifies that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the floor). Complete the following pseudocode model of the problem: Semaphore spaceOnTrain <- [0], Semaphore CrateOnTrain <- [10] Unloading Crane Loading Crane loop forever: [wait(crateOnTrain)] [unload crate from train] [signal(spaceOnTrain)] [put down crate on floor] loop forever: [pickup crate from floor] [wait(spaceOnTrain)] [load crate onto train] [signal(crateOnTrain)] Mark 10.00 out of Question 8 Correct 10.00 Flag question A goods train, capable of holding 10 crates, is to be loaded by one crane and unloaded by another. That is, one crane is always trying to load things onto the train and another crane is always trying to unload things from the train. Each crane is modelled as a thread in a computer simulation, two semaphores are used: spaceOnTrain specifies that there is room remaining on the train to load a crate; CrateOnTrain is used to guarantee that there is at least one crate on the train. The train initially arrives fully loaded with 10 crates and the cranes are not holding any crates. Cranes can operate in parallel with each other, but the loading crane must only load crates when there is space on the train; and the unloading crane can only pick up a crate when there is at least one crate on the train. No other activities of cranes should be blocked while the train is full/empty (i.e. cranes should be free to pickup and put down crates from the floor). Complete the following pseudocode model of the problem: loop forever: loop forever: Semaphore spaceOnTrain <- , Semaphore CrateOnTrain <- 0 10 Unloading Crane Loading Crane wait(crateOnTrain) unload crate from train signal(spaceOnTrain) put down crate on floor pickup crate from floor wait(spaceOnTrain) load crate onto train signal(crateOnTrain) Consider the following solution to the dining philosophers problem in which five philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) The correct answer is: Consider the following solution to the dining philosophers problem in which five philosophers: p,q,r,s and t must eat with the provided forks. Complete the statements below: The interleaving p1,p2,q1,q2,r1,r2,s1,s2,t1,t2 leads to [deadlock]. Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock [false]. Changing the order in which philosopher t picks up the forks will prevent deadlock [true]. Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock [true]. Week 4 Quiz - Assessed Coursework, Deadline 18/02/2020 @ 10am Mark 10.00 out of Question 1 Correct 10.00 Flag question Semaphore array fork <- [1,1,1,1,1] loop_forever p1: think p2: wait(fork[i]) //left fork p3: wait(fork[i+1]) //right fork p4: eat p5: signal(fork[i]) P6: signal(fork[i+1]) Theinterleavingp1,p2,q1,q2,r1,r2,s1,s2,t1,t2leadsto deadlock . Placing all the forks in the centre of the table and allowing each philosopher to take any one would prevent deadlock false . Changingtheorderinwhichphilosophertpicksuptheforkswillpreventdeadlock true . Adding an extra fork between (adjacent) philosophers t and p would prevent this from reaching deadlock true . Consider the follow diagram representing the states of threads in Java when using monitors. StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) Runnable (c) Running (1) start() (2) run() (3) yield() (4) wait() (5) notifyAll() The correct answer is: Consider the follow diagram representing the states of threads in Java when using monitors. StateDiagram Complete the text below indicating which Java methods could appear on each of the edges and which labels are appropriate for the remaining nodes. (b) [Runnable] (c) [Running] (1) [start()] (2) [run()] (3) [yield()] (4) [wait()] (5) [notifyAll()] (6) [run() ends] The scheduler can cause transitions on edges [2 and 3]. Mark 20.00 out of Question 2 Correct 20.00 Flag question (6) run()ends Theschedulercancausetransitionsonedges 2and3 . A programmer creates the following two Java classes: public class A { public synchronized void a1(){ //do something } public void a2(){ //do something } public synchronized int a3(){ int var = 0; //do something changing var return var; } } public class B { public void b1(){ //do something } public synchronized int b2(){ int var = 0; //do something changing var return var; } public void b3(){ //do something } } Then a main method which does the following: The precise details of the creation and function of the threads are not important, so they are not given, you may assume that they run in parallel and call methods on the created objects. Further you may assume that no other mechanisms that are not shown prevent methods from running concurrently. Which of the following groups of methods cannot be run concurrently (i.e. will be sequenced so that one finishes before the other starts) if called at the same time by two different threads? public static void main(String[] args){ A firstA = new A(); A secondA = new A(); B firstB = newB(); //create some threads that perform operations on firstA, secondA and first B and start them } The correct answers are: firstA.a1() and firstA.a3(), secondA.a3() and secondA.a3() Mark 10.00 out of Question 3 Correct 10.00 Flag question Select whether each of the following statements is true or false: If we impose the immediate resumption requirement and use the classical monitor priority scheme (Entering < Notifying < Waiting) and notify a singlethreaditissafetouseiftocheckwaitconditions True . OnlyobjectsthataredeclaredtoextendthreadorimplementrunnablehaveamonitorlockinJava False . Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of theresource True . Callingnotify()ratherthannotifyAll()canreducecontextswitchingoverheads True . Congratulations! The correct answer is: Select whether each of the following statements is true or false: If we impose the immediate resumption requirement and use the classical monitor priority scheme (Entering < Notifying < Waiting) and notify a single thread it is safe to use if to check wait conditions [True]. Only objects that are declared to extend thread or implement runnable have a monitor lock in Java [False]. Monitors are less likely to lead to bugs than semaphores as the management of concurrent access is encapsulated and managed by the creator of the resource [True]. Calling notify() rather than notifyAll() can reduce context switching overheads [True]. Mark 7.50 out of Question 4 Partially correct 10.00 Flag question This question is about Java programming using swing. Select whether each of the following statements is true or false: Methodsrunningintheeventdispatchthreadcannotaccessdatastructurescreatedinthemainthread. True . It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. False Threading problems cannot occur when using swing because it is thread safe. False . Alleventhandlersruninthemainthread. False . . You have correctly selected 3. Select one or more: firstA.a3() and secondA.a2() firstA.a1() and firstA.a3() before the other starts Synchronized methods in the same object cannot be run in parallel, the keyword synchronized requires one to complete secondA.a3() and firstB.b2() firstA.a3() and firstB.b1() firstB.b3() and firstB.b3() firstB.b1() and firstB.b3() secondA.a3() and secondA.a3() Synchronized methods in the same object cannot be run in parallel, and that includes with themselves, the keyword synchronized requires one to complete before the other starts. Two different threads can attempt to call the same method at once, think for example, of two producers calling produce at the same time firstB.b2() and firstB.b3() firstA.a3() and secondA.a3() firstA.a2() and secondA.a2() secondA.a2() and firstB.b3() The correct answer is: This question is about Java programming using swing. Select whether each of the following statements is true or false: Methods running in the event dispatch thread cannot access data structures created in the main thread. [False]. It is not possible to use more than two threads in a swing program: the main thread and the event dispatch thread. [False]. Threading problems cannot occur when using swing because it is thread safe. [False]. All event handlers run in the main thread. [False]. Mark 9.29 out of Question 5 Partially correct 10.00 Flag question Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. 1: public class CrossingUser extends Thread { 2: private String mode; 3: private Crossing crossing; 4: 5: public CrossingUser(Crossing toUse, String modeIn){ 6: 7: 8: 9: 10: 11: crossing.enterCrossing(this); 12: crossing.useCrossing(this); 13: crossing.leaveCrossing(this); 14: } 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: public int timeToCross(){ if(mode.equals("ROAD")){ return 50; } else { return 200; } } public String getMode(){ return mode; } } mode = modeIn; crossing = toUse; } public void run(){ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 13: 13: 14: public class Crossing { private String mode = ""; private int users = 0; public synchronized void enterCrossing(CrossingUser u){ while u.getMode().equals(mode) try{ } catch ( InterruptedException e.printStackTrace(); } } mode = u.getMode() ; ( !mode.equals("") ){ && e){ wait() ; 15: 16: Crossing"); 17: } 18: ++users; System.out.println(u.getMode() + " User Entering the public void 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: } Crossing"); 34: notifyAll() ; 35: } 36: } useCrossing(CrossingUser u){ Thread.sleep(u.timeToCross()) ; try{ } catch ( InterruptedException e){ e.printStackTrace(); } } public synchronized void --users; if(users == 0){ leaveCrossing(CrossingUser u){ ; System.out.println(u.getMode() + " User Leaving the mode = "" 32: 33: Your answer is partially correct. You have correctly selected 13. The correct answer is: Consider the following Java Classes which are intended to represent a pedestrian crossing, and its users. You are given the CrossingUser class and should complete the crossing class to enfroce the rule that foot and road users may not use the crossing simultaneously. Your code should not restrict the number of foot or road users that can use the crossing together. 1: public class CrossingUser extends Thread { 2: private String mode; 3: private Crossing crossing; 4: 5: public CrossingUser(Crossing toUse, String modeIn){ 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: mode = modeIn; crossing = toUse; } public void run(){ crossing.enterCrossing(this); crossing.useCrossing(this); crossing.leaveCrossing(this); } public int timeToCross(){ if(mode.equals("ROAD")){ return 50; } else { return 200; } } public String getMode(){ return mode; } } 1: public class Crossing { 2: 3: private String mode = ""; 4: private int users = 0; 5: 6: [public synchronized void] enterCrossing(CrossingUser u){ 7: [while]([!mode.equals("") ] [&&] [!u.getMode().equals(mode)]){ 8: 9: 10: 11: 13: 13: 14: 15: 16: the 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: leaveCrossing(CrossingUser u){ 28: 29: 30: 31: 32: 33: the 34: 35: 36: --users; if(users == 0){ [mode = ""]; } System.out.println(u.getMode() + " User Leaving Crossing"); [notifyAll()]; } } Crossing"); } } e.printStackTrace(); } try{ [wait()]; } catch ([InterruptedException] e){ [mode = u.getMode()]; ++users; System.out.println(u.getMode() + " User Entering [public void] useCrossing(CrossingUser u){ try{ [Thread.sleep(u.timeToCross())]; } catch ([InterruptedException] e){ e.printStackTrace(); } } [public synchronized void] Mark 10.00 out of Question 6 Correct 10.00 Flag question Now the following rules are to be enforced: It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2); No more than 1 road user can be on the crossing at the same time (restriction 3). Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You're answer will not be marked as correct unless you complete the restrictions in the specified order (this is a limitiation of KEATS, of course any order of the conditions would work in Java). while //restriction 1 //restriction 2 try {//etc. } ((!u.getMode().equals(mode) && (users>2 && (users>0 &&
!mode.equals(“”) u.getMode().equals(“FOOT”) u.getMode().equals(“ROAD”)
) || ) ||
)){ //restriction3
Your answer is correct.

The correct answer is:
Now the following rules are to be enforced:
It remains that no foot and road users can be on the crossing at the same time (restriction 1); No more than three pedestrians can be on the crossing at the same time (restriction 2);
No more than 1 road user can be on the crossing at the same time (restriction 3).
Complete this replacement for line 7 of the Crossing class that will enforce them. N.B. You’re answer will not be marked as correct unless you complete the restrictions in the specified order (this is a limitiation of KEATS, of course any order of the conditions would work in Java).
[while](([!u.getMode().equals(mode)] [&&] [!mode.equals(“”) ] ) [||] //restriction 1 ([users > 2] [&&] [u.getMode().equals(“FOOT”)]) [||] //restriction 2 ([users > 0] [&&] [u.getMode().equals(“ROAD”)])){ //restriction 3
try {//etc. }
Question 7
Mark 15.00 out of
Correct 15.00 Flag question
Consider the following method (and class variables), that are intended to enforce the following rules:
The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once;
Only one car can travel westbound at once.
int carCount = 0;
boolean westbound = false;
public synchronized void enterBridge(Vehicle v){ //block
westbound = v.getWestbound(); //set direction to your direction ++carCount; //increment cars using bridge
System.out.println(v + “ entering the bridge”);
}
Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of
the code is correctly implemented.
block 1:
while((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 2:
while((v.getWestbound() != westbound && carCount > 0) &&
(!v.getWestbound() && carCount > 2) && (v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 3:
if((v.getWestbound() != westbound && carCount > 0) ||
(!v.getWestbound() && carCount > 2) ||
(v.getWestbound() && carCount > 0)) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
block 4:
if((v.getWestbound() != westbound && carCount > 0)) {

The correct answer is: block 1
Mark 15.00 out of
Question 8 Correct 15.00 Flag question
if (!v.getWestbound() && carCount > 2) { if (v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
} }
block 5:
if((v.getWestbound() != westbound && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
if(!v.getWestbound() && carCount > 2) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
if(v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
block 6:
while((v.getWestbound() != westbound && carCount > 0)) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
while(!v.getWestbound() && carCount > 2) { try{
wait();
} catch (InterruptedException e){ e.printStackTrace();}
}
while(v.getWestbound() && carCount > 0) {
try{ wait();
} catch (InterruptedException e){ e.printStackTrace();} }
Select one or more:
b. block 2 c. block 3 d. block 4 e. block 5 f. block 6
a. block 1 Correct!
Consider the following methods to exit and cross the bridge that are to be a part of the same class as the previous enterBridge method.
public synchronized void exitBridge(Vehicle v){ –carCount;
System.out.println(v + “ exiting the bridge”); notifyAll();
}

The correct answers are: Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one., Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock., If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should.
Week 5 Quiz – Assessed Coursework, Deadline 10:00am 25/02/2019
Mark 17.78 out of
Question 1 Partially correct 20.00 Flag question
public void crossBridge(){ try{
Thread.sleep(100);
} catch (InterruptedException e){
e.printStackTrace(); }
}
Select all statements that are correct:
Select one or more:
Failling to decrement carCount (i.e. removing –carCount) would ultimately lead to deadlock.
three had entered because they would wait indefintely for car count to be low enough.
No threads will be needlessly blocked if notifyAll() is replaced with notify()
Correct! No cars would be able to enter the bridge once
If crossBridge was synchronized then three cars attempting to cross the bridge at the same time would take longer than should. Correct! The threads would each have to wait in turn to execute crossBridge, and could therefore not be sleeping at the same time.
Decrementing carCount in this method is safe because all other methods that modify it are synchrnoized with this one. Correct!
If the order of the println and notifyAll statements are swapped it is possible that another car will enter the bridge before the message exiting the bridge is printed.
For each of the following scenarios use the Banker’s algorithm to determine whether the system is in a safe or an unsafe state. If the system is safe, give the safe order that Banker’s algorithm would produce for the processes (you should assume that ties are broken by selecting the process with the smallest number when multiple processes are able to run). If the system is not in a safe state, give the order processes that have executed were executed in, and fill the remaining boxes with X. All allocations and requirements are specified for three resources in the order R1, R2, R3.
Scenario 1:
P0 max requirement 3,4,0 and allocation 0,0,0. P1 max requirement 1,3,0 and allocation 0,1,0. P2 max requirement 4,0,4 and allocation 3,0,2. P3 max requirement 0,2,0 and allocation 0,1,0. P4 max requirement 1,4,4 and allocation 0,0,0.
The current resource availability is:1,2,2. The system is in a Safe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P1 P2 P3 P4 P0 Scenario 2:
P0 max requirement 4,0,0 and allocation 2,0,0. P1 max requirement 0,0,1 and allocation 0,0,0. P2 max requirement 3,2,8 and allocation 1,0,4. P3 max requirement 1,1,1 and allocation 0,0,0. P4 max requirement 2,0,3 and allocation 0,0,1.
The current resource availability is:1,2,3. The system is in a Unsafe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P1 P3 X X X

Mark 7.50 out of
Question 2 Partially correct 10.00 Flag question
Select whether each of the following statements is true or false:
deadlockonlyoccurswhenallinterleavingsofaprogramleadtodeadlock False . Ifthesystemisinanunsafestatethendeadlockmightoccur True .
The resource allocation graph algorithm can be used to check for deadlock when there are multiple instances of each resource True . Deadlock can occur if there is only one process runnning False .
You have correctly selected 3.
The correct answer is:
Select whether each of the following statements is true or false:
deadlock only occurs when all interleavings of a program lead to deadlock [False].
If the system is in an unsafe state then deadlock might occur [True].
The resource allocation graph algorithm can be used to check for deadlock when there are multiple instances of each resource [False]. Deadlock can occur if there is only one process runnning [False].
Mark 10.00 out of
Question 3 Correct 10.00 Flag question
Scenario 3:
P0 max requirement 0,4,7 and allocation 0,2,6. P1 max requirement 2,1,0 and allocation 0,0,0. P2 max requirement 4,0,7 and allocation 2,0,0. P3 max requirement 1,2,1 and allocation 0,0,0. P4 max requirement 1,0,0 and allocation 0,0,0.
The current resource availability is:2,2,1. The system is in a Safe
state.
The safe order or order in which processes would execute in the Banker’s algorithm is:
P0 P1 P2 P3 P4
Consider the following code:
public class myFirstThread extends Thread {
Semaphore s1,s2,s3;
public myFirstThread(Semaphore a, Semaphore b,
s1 = a; s2 = b; s3 = c;
}
public void run(){
Semaphore c){
//first thread implementation }
}
public class mySecondThread extends Thread {
Semaphore s1,s2,s3;
public mySecondThread (Semaphore a, Semaphore b,
s1 = a; s2 = b; s3 = c;
}
public void run(){
Semaphore c){
//second thread implementation }
}

The correct answers are: a, b
Mark 3.33 out of
Question 4 Partially correct 10.00 Flag question
Which of the following pairs of implementations of the run methods can deadlock? Exception handling code (try, catch) has been omitted for clarity.
first thread implementation
second thread implementation
a
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s2.release();
}
b
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s1.acquire(); s3.acquire(); s3.release(); s1.release();
}
c
public void run(){ s1.acquire(); s3.release();
}
public void run(){ s3.acquire(); s1.release();
}
d
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
public void run(){ s3.acquire(); s1.acquire(); s3.release(); s1.release();
}
e
public void run(){ s1.acquire(); s1.release();
}
public void run(){ s3.acquire(); s3.release();
}
f
public void run(){ s2.acquire(); s1.acquire(); s1.release(); s2.release();
}
public void run(){ s1.acquire(); s2.acquire(); s2.release(); s1.release();
}
g
public void run(){ s1.acquire(); s3.acquire(); s1.release(); s3.release();
}
public void run(){ s1.acquire(); s1.release();
}
Select one or more:
c d e f g
a Correct! Since s1 is not signalled by t2 after being acquired it will become zero and both threads could end up waiting for it. b What happens if t1 acquires s1 then t2 acquires s3?
public
static void main(String[] args){
}
Semaphore s1 = new Semaphore(1); Semaphore s2 = new Semaphore(2); Semaphore s3 = new Semaphore(1);
Thread t1 = new myFirstThread(s1,s2,s3); Thread t2 = new mySecondThread(s1,s2,s3); t1.start();
t2.start();

The correct answers are: This program will almost certainly deadlock if ran for long enough., If the keyword synchronized was removed from the addItem method the program could not deadlock., If the keyword synchronized was removed from the addItem method loss of data could occur.
Mark 10.00 out of
Question 5 Correct 10.00 Flag question
Consider the following concurrent program:
Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 LeadstoDeadlock .
p1,p2,p3,q1,q2,q3 Does not Necessarily Lead to Deadlo.ck p1,p2,q1,q2,p3,q3 LeadstoDeadlock . p1,q1,p2,p3,q2,q3 Does not Necessarily Lead to Deadlo.ck
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Select one or more: a. This program is guaranteed to deadlock. b. This program will almost certainly deadlock if ran for long enough. c. This program is unlikely to deadlock in a short time period. d. This program can never deadlock. e. If the keyword synchronized was removed from the addItem method the program could not deadlock. f. If the keyword synchronized was removed from the addItem method loss of data could occur. public class Buffer { ArrayList messages;
public Buffer(){
messages = new ArrayList(); messages.add(“Hello”); messages.add(“World”);
}
public synchronized void moveFirstItemTo(Buffer other){
if(!messages.isEmpty()){
other.addItem(messages.remove(0)); }
}
public synchronized void addItem(String message){
messages.add(message); }
}
public class BufferUser extends Thread { Buffer b1;
Buffer b2;
public BufferUser(Buffer firstBuffer, Buffer secondBuffer){
b1 = firstBuffer;
b2 = secondBuffer; }
public void run(){ while(true){
b1.moveFirstItemTo(b2); }
} }
public static void main(String[] args) { Buffer b1 = new Buffer();
Buffer b2 = new Buffer();
BufferUser t1 = new BufferUser(b1,b2);
BufferUser t2 = new BufferUser(b2,b1);
t1.start();
t2.start(); }

The correct answer is:
Consider the following concurrent program:
Determine whether each of the following interleavings necessarily leads to deadlock? p1,q1,p2,q2,p3,q3 [Leads to Deadlock].
p1,p2,p3,q1,q2,q3 [Does not Necessarily Lead to Deadlock].
p1,p2,q1,q2,p3,q3 [Leads to Deadlock].
boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false p1,q1,p2,p3,q2,q3 [Does not Necessarily Lead to Deadlock]. Mark 5.00 out of Question 6 Partially correct 10.00 Flag question The number of possible interleavings of i threads (assuming all interleavings are valid) is given by the formula: (n1+n2 + ... + ni)!/(n1!*n2!*...*ni!)) where ni is the number of atomic instructions in thread i. Assuming each line of the following program represents an atomic instruction complete the following statement: There are 20 possible interleavings of this program of which 6 lead to deadlock. boolean wantp <- false, wantq <- false p q p1: non-critical section p2: wantp <- true p3: await wantq = false q1: non-critical section q2: wantq <- true q3: await wantp = false Mark 20.00 out of Question 7 Correct 20.00 Flag question For each of the following scenarios use the Banker's algorithm to determine whether the system is deadlocked. If the system is deadlocked, give the processes involved in the deadlock; if not set all to X. All allocations and requests are specified for three resources in the order R1, R2, R3. Scenario 1: P0 requested 0,2,2 and allocation 1,0,0. P1 requested 2,2,0 and allocation 0,0,0. P2 requested 0,0,1 and allocation 0,0,1. P3 requested 0,1,0 and allocation 0,0,0. P4 requested 0,2,1 and allocation 0,0,0. The current resource availability is: 2,2,1. Thesystemis NotDeadlocked . The following processes are deadlocked (enter X if the process is NOT deadlocked): XXXXX Scenario 2: P0 requested 0,0,0 and allocation 1,0,1. P1 requested 1,0,1 and allocation 0,1,0. P2 requested 1,1,2 and allocation 0,0,0. P3 requested 2,2,1 and allocation 0,2,1. P4 requested 2,1,1 and allocation 0,0,0. The current resource availability is: 1,0,1. Thesystemis Deadlocked Mark 10.00 out of Question 8 Correct 10.00 Flag question Which of the following resource allocation graphs represent a deadlocked system? a b c d Select one: None of them. b and d only. c and d only a and b only. a, b and d only. b. c and d only. a, c and d only. All of them. d only. The correct answer is: c and d only Week 6 Quiz - Deadline 10:00 am on Tuesday 03/3/2020 Mark 5.00 out of Question 1 Correct 5.00 Flag question Your answer is correct. The correct answer is: compile-time binding Absolute code can be generated for : Select one: a. interrupt binding b. excution-time binding c. compile-time binding d. load-time binding . The following processes are deadlocked (enter X if the process is NOT deadlocked): X X X P3 X Scenario 3: P0 requested 2,0,0 and allocation 1,0,0. P1 requested 1,2,0 and allocation 1,0,0. P2 requested 2,2,2 and allocation 0,1,0. P3 requested 0,2,1 and allocation 1,0,1. P4 requested 0,0,1 and allocation 0,1,0. The current resource availability is: 0,0,2. Thesystemis Deadlocked . The following processes are deadlocked (enter X if the process is NOT deadlocked): P0 P1 P2 P3 X Mark 5.00 out of Question 2 Correct 5.00 Your answer is correct. The correct answer is: Execution time binding Mark 5.00 out of Question 3 Correct 5.00 Flag question ---------------------- is the method of binding instructions and data to memory performed by most general-purpose operating systems. Select one: a. Compile time binding b. Load-time binding c. Interrupt binding d. Execution time binding Flag question Suppose a program is operating with execution-time binding and the physical address generated is 300. The relocation register is set to 100. What is the corresponding logical address? Select one: a. 300 b. 100 c. 199 d. 200 Your answer is correct. The correct answer is: 200 Mark 5.00 out of Question 4 Correct 5.00 Your answer is correct. The correct answer is: memory-management-unit (MMU) Mark 5.00 out of Question 5 Correct 5.00 Flag question The mapping of a logical address to a physical address is done in hardware by the ________. Select one: a. dynamic loading register b. memory address register c. memory-management-unit (MMU) d. relocation register Flag question _____ is the dynamic storage-allocation algorithm which results in the smallest leftover hole in memory. Select one: a. None of the options b. Best fit c. First fit d. Worst fit Your answer is correct. The correct answer is: Best fit Mark 5.00 out of Question 6 Correct 5.00 Flag question The roll out, roll in variant of swapping is used ____. Select one: a. when the load on the system has temporarily been reduced b. when a backing store is not necessary c. for the round-robin scheduling algorithm d. for priority-based scheduling algorithms Your answer is correct. The correct answer is: for priority-based scheduling algorithms Mark 1.67 out of Question 7 Partially correct 5.00 Flag question This question is about contiguous memory allocation, where memory is divided into used and unused blocks of memory, of varying sizes. Which of the following statements about contiguous memory allocation are true: Select one or more: a. Contiguous memory allocation suffers from external fragmentation c. When using contiguous memory allocation for processes, compaction can be used to fix external fragmentation d. Round-robin scheduling relies on contiguous memory allocation b. In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100. Correct - this would leave 0 bytes free The correct answers are: Contiguous memory allocation suffers from external fragmentation, In practice, if we have a hole of size 100, we can use this to satisfy a memory allocation of size 100., When using contiguous memory allocation for processes, compaction can be used to fix external fragmentation Mark 10.00 out of Question 8 Correct 10.00 Flag question Consider the following Java code: 1234: public class SomeCode { 1235: public static int v = 7; 1236: public static int w = 6; 1237: public static void a() { 1238: int t = 8; 1239: v = v + t; 1240: t = t * 2; 1241: w = w + t; 1242: b(t); 1243: System.out.println(v + w); 1244: } 1245: public static void b(int param) { 1246: int s = 5; 1247: for (int i = 0; i < 3; ++i) { 1248: s = s + param; 1249: } Mark 5.00 out of Question 9 Correct 5.00 Flag question Which of the following statements about paged memory allocation are true? Select one or more: b. Every call to 'new' requests another frame of memory, to store the resulting object. c. When using paging, logical addresses are split into a page number, and an offset Correct! The top-most bits are the page number; the bottom- most bits are the offset. d. Using paging can lead to external fragmentation between frames of allocated memory. a. Paging is based on diving memory into frames, the size of which are a power of two Correct! (The power of two bit is important.) The correct answers are: Paging is based on diving memory into frames, the size of which are a power of two, When using paging, logical addresses are split into a page number, and an offset Mark 10.00 out of Question 10 Correct 10.00 Flag question 1251: // What is on the stack here? 1252: } What is printed to the screen when this code executes? 38 What values are on the stack when execution reaches line 1251? Start filling in these boxes at the right hand side -- i.e. the item on the bottom of the stack goes in the rightmost box. If there are more boxes than you need, then fill the spare left-hand boxes with 0. Note, you should enter the values of variables on the stack, not their names; and you don't need to include the 'args[]' passed to main(). 0 0 0 53 1243 16 16 1257 42 1253: public static void main(String[] args) { 1254: int douglas = 40; 1255: douglas = douglas + 2; 1256: a(); 1257: System.exit(0); 1258: } 1259: } 1250: v = v + 1; For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; •Ifintvariablesare32bits,whatisthesizeofobjectofthisclass,inbytes? 12 The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } •Atthispoint,howmuchmemoryisusedtostoreCoordinateobjects? 216 • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to storeMemoryControlBlocks? 288 Your answer is correct. The correct answer is: For this question, assume the size of a memory control block is 16 bytes, and that you are using a contiguous memory allocation model. Consider the following class: class Coordinate { public: int x; int y; int z; }; • If int variables are 32 bits, what is the size of object of this class, in bytes? [12] The following code is then executed: for (int i = 0; i < 18; ++i) { new Coordinate(); } • At this point, how much memory is used to store Coordinate objects? [216] • If we are using a contiguous memory allocation model, starting with one hole of size 10000 bytes, how much of this memory has now been used to store Memory Control Blocks? [288] Mark 5.00 out of Question 11 Correct 5.00 Flag question A relocation register is used to check for invalid memory addresses generated by a CPU. Select one: a. TRUE b. FALSE Your answer is correct. The correct answer is: FALSE Mark 5.00 out of Question 12 Correct 5.00 Flag question _____ is the dynamic storage-allocation algorithm which results in the largest leftover hole in memory. Select one: a. None of the above b. Best fit c. Worst fit d. First fit Your answer is correct. The correct answer is: Worst fit Question 13 Correct Mark 5.00 out of 5.00 Flag question Assume a system has a TLB hit ratio of 90%. It requires 15 nanoseconds to access the TLB, and 85 nanoseconds to access main memory. What is the effective memory access time in nanoseconds for this system? Select one: a. 176.4 b. 22 c. 108.5 d. 100 Your answer is correct. The correct answer is: 108.5 Question 14 Correct Mark 5.00 out of 5.00 Flag question Consider a logical address with 18 bits used to represent an entry in a conventional page table. How many entries are in the conventional page table? Select one: a. 1048576 b. 1024 c. 18 d. 262144 Your answer is correct. The correct answer is: 262144 Question 15 Partially correct Mark 1.67 out of 5.00 Flag question Assume the value of the base and limit registers are 1200 and 350 respectively. Which of the following addresses is legal? Select one: a. 1551 b. all of the above c. 1200 d. 355 Your answer is partially correct. The correct answer is: 1200 Mark 5.00 out of Question 16 Correct 5.00 Flag question What is the context switch time, associated with swapping, if a disk drive with a transfer rate of 2 MB/s is used to swap out part of a program that is 200 KB in size? Assume that no seeks are necessary and that the average latency is 15 ms. The time should reflect only the amount of time necessary to swap out the process. Select one: a. 100 ms b. 113 ms Your answer is correct. The correct answer is: 113 ms Mark 5.00 out of Question 17 Correct 5.00 Flag question What is the advantage of using dynamic loading? Select one: a. dynamic loading allows the system to obtain better memory-space utilization b. With dynamic loading a program does not have to be stored, in its entirety, in main memory c. All of the options are correct d. dynamic loading allows unused routines to stay out of main memory so that memory can be used more effectively Your answer is correct. The correct answer is: All of the options are correct Mark 5.00 out of Question 18 Correct 5.00 Flag question Hashed page tables are particularly useful for processes with sparse address spaces. Select one: a. FALSE b. TRUE Your answer is correct. The correct answer is: TRUE Information Flag question This is the end of the quiz questions - submit your work when you are happy. Remember, once you have pressed submit, you cannot change your answers. Week 7 Coursework - KEATS Quiz, Deadline 10:00 am Tuesday 10/03/2020 Mark 20.00 out of Question 1 Correct 20.00 Flag question c. 120 ms d. None of the options A 32-bit computer has a virtual-memory space of 2^32 bytes. The computer is using memory paging, and the page size is 2^9 (i.e. 512) bytes. How many bits of the memory address are used for the page number? 23 How many bits of the memory address are used for the offset? 9 If each physical memory address is stored in 32-bits (i.e. 2^2 bytes), how large is the page table, in bytes? Give your answer as a power of two - e.g. if your answer is (2^10), then enter 10 into the box. Page table size = 2^ 25 Mark 20.00 out of Question 2 Correct 20.00 Flag question Information Flag question Thrashing is bad, m'kay. But which of the following would the situation worse, better, or have no effect at all? Mark 5.00 out of Question 3 Correct 5.00 Flag question The correct answer is: Have no effect on the amount of thrashing Mark 5.00 out of Consider a system with 3 frames of memory and the following sequence of page accesses: 2, 3, 1, 0, 3, 1, 2, 3, 0, 1, 2, 0, 3, 0, 1 When do page faults occur using the FIFO and LRU page replacement algorithms? Enter your answer as a string, comprising the letters Y and N, where Y means there was a page fault, and N means there was not. For instance, if you think there were three page faults to start with, and then no page faults after that, enter YYYNNNNNNNNNNNN Do not include any spaces or punctuation in your answer. FIFO Page faults: YYYYNNYYNYNYNNN LRU Page faults: YYYYNNYNYYYNYNY Adding a bigger hard drive will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing c. Have no effect on the amount of thrashing Correct - a bigger hard drive would have more free space, but the bottleneck is the time taken to swap pages to/from disk. Question 4 Correct 5.00 The correct answer is: Reduce the amount of thrashing Mark 5.00 out of Question 5 Correct 5.00 Flag question Terminating some processes (closing some programs) will: Select one: a. Increase the amount of thrashing b. Reduce the amount of thrashing Correct - if we terminate some processes, then memory is freed up, reducing the amount of thrashing. c. Have no effect on the amount of thrashing Flag question Adding more memory to the machine will: Select one: a. Increase the amount of thrashing c. Have no effect on the amount of thrashing b. Reduce the amount of thrashing Correct - adding more memory increases how much memory each process can use, reducing the number of page faults, and hence reducing thrashing. The correct answer is: Reduce the amount of thrashing bytes. Mark 5.00 out of Question 6 Correct 5.00 The correct answer is: Reduce the amount of thrashing Mark 5.00 out of Question 7 Correct 5.00 Flag question Rewriting code to have a smaller working set (locality) will: Select one: a. Increase the amount of thrashing c. Have no effect on the amount of thrashing b. Reduce the amount of thrashing Correct - if we can get the total working set size to be less than the amount of physical memory in the machine, we can hope to eliminate thrashing. Flag question In systems that support virtual memory, ____. Select one: a. physical memory is separated from logical memory. b. virtual memory is separated from physical memory. c. physical memory is separated from secondary storage. d. virtual memory is separated from logical memory. Your answer is correct. The correct answer is: physical memory is separated from logical memory. Question 8 Correct Mark 10.00 out of 10.00 Flag question Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what is the number of page faults for the given reference string? Select one: 10 13 8 14 Your answer is correct. The correct answer is: 8 Question 9 Correct Mark 10.00 out of 10.00 Flag question Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the FIFO replacement algorithm, what will be the final configuration of the three frames following the execution of the given reference string? Select one: a. 4, 1, 3 b. 3, 1, 4 c. 3, 4, 2 d. 4, 2, 3 Your answer is correct. The correct answer is: 3, 4, 2 Mark 5.00 out of Question 10 Correct 5.00 Flag question Your answer is correct. The correct answer is: for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases Mark 5.00 out of Question 11 Correct 5.00 Flag question Belady's anomaly states that ____. Select one: a. for some page replacement algorithms, the page-fault rate may decrease as the number of allocated frames increases b. giving more memory to a process will improve its performance c. for some page replacement algorithms, the page-fault rate may increase as the number of allocated frames increases d. as the number of allocated frames increases, the page-fault rate may decrease for all page replacement algorithms Optimal page replacement ____. Select one: is used mostly for comparison with other page-replacement schemes requires that the system keep track of previously used pages is the page-replacement algorithm most often implemented can suffer from Belady's anomaly Your answer is correct. The correct answer is: is used mostly for comparison with other page-replacement schemes Mark 5.00 out of Question 12 Correct 5.00 Flag question _____ is the algorithm implemented on most systems. Select one: LRU Most frequently used Least frequently used FIFO Your answer is correct. The correct answer is: LRU Week 8 Coursework - Deadline: 10:00, 20th of March 2020 Mark 5.00 out of Question 1 Correct 5.00 Flag question Which of the following two statements are security problems that can arise and need to be protected against when users simultaneously share a computing system -- i.e. they would not otherwise be an issue on a single-user system Select one or more: a. Users can accidentally delete their files from disk b. One user's process might access the memory of another user's process Yes, in principle, if one user's process accessed the memory of another The correct answers are: One user's process might access the memory of another user's process, Confidential files kept on disk could be accessed by any user Mark 5.00 out of Question 2 Correct 5.00 Flag question Your answer is correct. The correct answer is: An advantage of compiler-based enforcement of access control is[access] privileges are closely related to the [linguistic ] concept of a data type. Mark 5.00 out of Question 3 Correct 5.00 Flag question Your answer is correct. The correct answer is: The [users] normally decide the contents of the access-matrix entries. Mark 5.00 out of Question 4 Correct 5.00 Flag question Your answer is correct. The correct answer is: The [access matrix] provides an appropriate mechanism for defining and implementing [strict control] for both the [static] and [dynamic] association between processes and domains. Mark 5.00 out of Question 5 Correct 5.00 Flag question Your answer is correct. The correct answer is: it is difficult to take advantage of special groupings of objects or domains when implementing [access matrix] using a [global table] Mark 5.00 out of Question 6 Correct 5.00 Flag question Anadvantageofcompiler-basedenforcementofaccesscontrolisaccess privilegesarecloselyrelatedtothe linguistic concept of a data type. The users normallydecidethecontentsoftheaccess-matrixentries. The accessmatrix providesanappropriatemechanismfordefiningandimplementing strictcontrol forboththe static and dynamic associationbetweenprocessesanddomains. itisdifficulttotakeadvantageofspecialgroupingsofobjectsordomainswhenimplementing accessmatrix usinga global table c. The system might start to run unacceptably slowly d. Confidential files kept on disk could be accessed by any user It's important to use access control to ensure users can have private files that only they (and systems administrators) can access. user's process, it could, for instance, look at what document they were currently editing. Process P should be able to switch from domain Di to domain Dj if and only if the ∈ access(i, j). access right switch Your answer is correct. The correct answer is: Process P should be able to switch from domain Di to domain Dj if and only if the [access right] [switch ] ∈ access(i, j). Mark 4.00 out of Question 7 Correct 4.00 Flag question Your answer is correct. The correct answer is: The [copy and owner] rights allow a process to change the entries in a column in the access matrix and the [control ] rights applicable to [domain] objects only. Mark 5.00 out of Question 8 Correct 5.00 Flag question Your answer is correct. The correct answer is: The [capability] list is a [protected ]object maintained by [operating system ]and accessed by [users] only [indirectly]. Mark 5.00 out of Question 9 Correct 5.00 Flag question Your answer is correct. The correct answer is: Most systems use a combination of [access list and capabilities ] . When a process first tries to access an object, the [access list ] is searched. If access is denied, an exception condition occurs. Otherwise, a [capability ] is created and attached to the process. Mark 3.00 out of Question 10 Correct 3.00 Flag question The copyandowner rightsallowaprocesstochangetheentriesinacolumnintheaccessmatrixandthe control rightsapplicableto domain objectsonly. The capability list is a protected object maintained by operating system and accessed by users only indirectly . Mostsystemsuseacombinationof accesslistandcapabilities .Whenaprocessfirsttriestoaccessanobject,the accesslist issearched.Ifaccessisdenied,anexceptionconditionoccurs.Otherwise,a capability is created and attached to the process. Enforcementby programminglanguages is more flexible thanenforcementbythe kernel for user-defined policy Your answer is correct. The correct answer is: Enforcement by [kernel ] is [less] [flexible] than enforcement by the [programming languages ] for user-defined policy Comment: Mark 3.00 out of Question 11 Correct 3.00 Flag question Your answer is correct. The correct answer is: In [Java], when a class is [loaded], the [JVM] assigns the class to a [protection ] domain that gives the [permissions ] of that class. Mark 5.00 out of Question 12 Correct 5.00 Flag question Your answer is correct. The correct answer is: A[confinement] problem is the problem of [ guaranteeing] that no [information] initially held in an [object] can migrate outside of its execution environment. Mark 5.00 out of Question 13 Correct 5.00 Flag question Your answer is correct. The correct answer is: The principle of least [privileges] means that programs, users, and even systems be given [just enough] privileges to perform their [tasks]. Mark 5.00 out of Question 14 Correct 5.00 Flag question Your answer is correct. The correct answer is: [Windows 2000] has a complex protection scheme at its core and yet has many security holes. In Java , when a class is loaded , the JVM assigns the class to a protection domain that givesthe permissions ofthatclass. Aconfinement problemistheproblemof guaranteeing thatno information initiallyheldinan object can migrate outside of its execution environment. The principle of least privileges means that programs, users, and even systems be given just enough privileges to perform their tasks . Windows 2000 has a complex protection scheme at its core and yet has many security holes. Mark 5.00 out of Question 15 Correct 5.00 Flag question Your answer is correct. The correct answer is: The [need-to-know] principle, is useful in limiting the amount of damage a faulty process can cause in the system. Mark 5.00 out of Question 16 Correct 5.00 Flag question Your answer is correct. The correct answer is: The association between a [process] and a [domain]may be either [static ] or [dynamic]. Mark 5.00 out of Question 17 Correct 5.00 Flag question Your answer is correct. The correct answer is: In the [MULTICS] system, the protection domains are organized hierarchically into a [ring structure]. Mark 5.00 out of Question 18 Correct 5.00 Flag question The need-to-know principle,isusefulinlimitingtheamountofdamageafaultyprocesscancauseinthesystem. Theassociationbetweena process anda domain maybeeither static or dynamic . Inthe MULTICS system,theprotectiondomainsareorganizedhierarchicallyintoa ringstructure . Which of the following statements is not TRUE about Compiler Based Enforcement? Select one: Protection needs are declared, rather than programmed. The means for enforcement need to be provided by the designer of a subsystem. Protection is embedded in linguistic concept of data type. Protection requirements can be defined independently of any particular operating system facilities. Your answer is correct. The correct answer is: The means for enforcement need to be provided by the designer of a subsystem. Mark 5.00 out of Question 19 Correct 5.00 Flag question Stack inspection is : Select one: All the options are correct Protection mechanism provided in Java programming language Useful for inspecting classes from un trusted sources Providing methods to request access to a protected resource either directly or indirectly Your answer is correct. The correct answer is: All the options are correct Mark 10.00 out of Question 20 Correct 10.00 Flag question Consider the following file-access-control situations. For each, choose whether it could be encoded using the standard UNIX owner/group/other permissions model - and if so, choose appropriate users, groups and permissions If you do not think the permissions can be written in owner/group/other format, choose 'No' then pick the 'It cannot be done' option for the other answers to that question. a) Harry creates a file. He wants to give read/write access to Ron and Hermione, and no access to anyone else. Can this be done using the owner/group/other model? Yes If so: Who would be the owner of the file? Harry Who would be in the group for the file? Ron: Yes Hermione: Yes What would their permissions be? rw- What would the 'other' permissions be? --- b) Voldemort creates a file. He wants to give Snape read/write access, Bellatrix read-only access, and no access to anyone else. Can this be done using the owner/group/other model? No If so: Who would be the owner of the file? Neither/it cannot be done Who would be in the group for the file? Snape: No/itcannotbedone Bellatrix: No/itcannotbedone What would their permissions be? Neither/it cannot be done What would the 'other' permissions be? Neither/it cannot be done c) Filch creates a file. He wants to give staff read/write access, and other users (e.g. pupils) read-only access. Can this be done using the owner/group/other model? Yes If so: Who would be the owner of the file? Filch Who would be the group for the file? Staff What would their permissions be? rw- What would the 'other' permissions be? r-- Week 9 Quiz - Extended Deadline 10:00, March the 30th for students who have been in isolation due to corona virus. Mark 10.00 out of Question 1 Correct 10.00 Your answer is correct. The correct answer is: a Trojan horse Mark 10.00 out of Question 2 Correct 10.00 Your answer is correct. The correct answer is: All the three options Mark 8.00 out of Question 3 Correct 8.00 Your answer is correct. The correct answer is: All the three options Mark 10.00 out of Question 4 Correct 10.00 Your answer is correct. Flag question A code segment that misuses its environment is called Select one: a trap door a back door a Trojan horse a worm Flag question A worm Select one: All the three options continue to grow as the Internet expands can shut down an entire network use the spawn mechanism to ravage system performance Flag question The backdoor program is Select one: Used in distributed attacks that focus on the malicious modification to software/hardware at the factory time. All the three options Used in distributed attacks that focus on the malicious modification to software/hardware at the distribution time Used to gain unauthorized access to information Flag question Modern Cryptography is based on secrets called keys that are selectively distributed to computers in a network and used to process messages. The correct answer is: Modern [Cryptography] is based on [secrets] called [keys]that are selectively distributed to computers in a network and used to process messages. Mark 8.00 out of Question 5 Correct 8.00 Your answer is correct. The correct answer is: D-denial of service Mark 10.00 out of Question 6 Correct 10.00 Flag question Which of the following attacks is not type of social engineering attacks ? Select one: Baiting Phishing D-denial of service Pretexting Flag question In a paired-password system, Select one: two users must enter their own separate password to gain access to the system passwords must contain equal amounts of numbers and digits paired together the computer supplies one part of a password and the user enters the other part the user specifies two passwords Your answer is correct. The correct answer is: the computer supplies one part of a password and the user enters the other part Mark 8.00 out of Question 7 Correct 8.00 Flag question Your answer is correct. The correct answer is: The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. Mark 8.00 out of Question 8 Correct 8.00 Flag question The concept "system reliability" means: Select one: The probability of a system to function correctly continuously over a given period of time under a given set of operation conditions. The Probability of a system that will be functioning without errors during daytime None of the three options The Probability of a system that will be functioning correctly at any given time boot A file A macro An encrypted virusinfectsthe boot sectorofthesystem viruschangesthestartoftheprogramsothatexecutionjumpstoits code . is written in high level programming languages. virusincludes decryption codealongwiththeencryptedvirus. Tunneling virus attempts to bypass detection by an antivirus by installing itself in the interrupt handler chain Your answer is correct. The correct answer is: [boot] virus infects the [boot] sector of the system A [file] virus changes the start of the program so that execution jumps to its [code]. A [macro] is written in [high] level programming languages. An [encrypted] virus includes [decryption]code along with the encrypted virus. [Tunneling ] virus attempts to bypass detection by an antivirus by installing itself in the [interrupt handler ] chain Mark 0.00 out of Question 9 Incorrect 8.00 Flag question Your answer is incorrect. The correct answer is: Users with privileged system rights have constrained internet and email access from their privileged account Mark 10.00 out of Question 10 Correct 10.00 Flag question Your answer is correct. The correct answer is: A [worm]is structured as a complete, standalone program whereas a [virus] is a fragment of code embedded in a legitimate program. Mark 10.00 out of Question 11 Correct 10.00 Flag question Your answer is correct. The correct answer is: RC4 Limit privileged user functionality means: Select one: None of the three options Users with privileged system rights have constrained internet and email access from their privileged account Users with ‘normal’ privileges should be prevented from installing or disabling any software or services running on the system. Administrators have full internet and email access from their privileged account A worm is structured as a complete, standalone program whereas a virus is a fragment of code embedded in a legitimate program. ----------- isasymmetricstreamcipher Select one: None of the three options AES RC4 DES