0% found this document useful (0 votes)
14 views4 pages

COS226 2022 - Semester Test 1

The document is a memo for a Semester Test I for the COS 226 course at the University of Pretoria, dated 19 August 2022. It includes instructions for the test, a list of 16 questions covering various topics in concurrent systems, and marks allocated for each question. The memo emphasizes academic integrity and prohibits any form of cheating or collaboration during the assessment.

Uploaded by

mvanheerdentuks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

COS226 2022 - Semester Test 1

The document is a memo for a Semester Test I for the COS 226 course at the University of Pretoria, dated 19 August 2022. It includes instructions for the test, a list of 16 questions covering various topics in concurrent systems, and marks allocated for each question. The memo emphasizes academic integrity and prohibits any form of cheating or collaboration during the assessment.

Uploaded by

mvanheerdentuks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Engineering, Built Environment and IT

Department of Computer Science


Concurrent Systems
COS 226
Semester Test I Memo

19 August 2022

Instructions
1. Read the question paper carefully and answer all the questions below.
2. Answer all question is the answer book provided.
3. The assessment opportunity comprises of 16 questions on 4 pages.
4. You have 1 hour to complete the paper.
5. You are not allowed to copy from any source. Use your own insight and opinions when answering the questions.
6. This paper is subject to the University of Pretoria Integrity statement provided below.
• You are not allowed to discuss the questions with anyone.
Integrity statement:
The University of Pretoria commits itself to produce academic work of integrity. I affirm that I am aware of and have
read the Rules and Policies of the University, more specifically the Disciplinary Procedure and the Tests and Examinations
Rules, which prohibit any unethical, dishonest or improper conduct during tests, assignments, examinations and/or any
other forms of assessment. I am aware that no student or any other person may assist or attempt to assist another
student, or obtain help, or attempt to obtain help from another student or any other person during tests, assessments,
assignments, examinations and/or any other forms of assessment.

Question: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Total
Marks: 2 2 2 1 2 2 2 4 11 3 4 2 4 3 4 2 50

1
1. Which one of the following is not a genuine conflict in a concurrent environment ? (2)
(a) reader-reader conflict
(b) reader-writer conflict
(c) write-write conflict
(d) None of the above.

2. Which one of the following statements is true: (2)


(a) Deadlock-freedom also implies starvation-freedom
(b) Starvation-freedom also implies deadlock-freedom
(c) Starvation-freedom also implies fairness
(d) Deadlock-freedom also implies mutual exclusion
3. With respect to the behaviour of concurrent objects which of the following is not a condition of object correctness. (2)
(a) Concurrent consistency.
(b) Quiescent consistency.
(c) Linearizability.
(d) Sequential consistency.
4. Volatile fields are linearizable. (true or false) (1)
(a) true
(b) false

5. Why is starvation freedom considered to be a weak property (2)


(a) Because there is no guarantee of the duration threads will wait for a lock.
(b) Because starvation freedom does not guarantee dead lock freedom.
(c) Because starvation freedom is not a liveness property.
(d) Because starvation freedom is not a safety property.
6. In a concurrent environment under what circumstances does quiescent consistency require one method call to (2)
block waiting for another to complete?
(a) When the method call has occurred but before the method returns.
(b) Before method invocation.
(c) In between method calls.
(d) Never.
7. The Peterson lock was designed to synchronize only two threads. What would happen if we used the Peterson (2)
lock for more than two threads?
(a) The system would deadlock
(b) One or more of the threads would starve
(c) There will no longer be mutual exclusion
(d) The system would not be fair

8. (a) What is considered to be the weakest of all concurrent registers. (2)


Sol: A safe [1/2], boolean [1/2], single-reader [1/2], single-writer [1/2] register
(b) What is considered to be the strongest of all concurrent registers. (2)
An atomic [1/2], M-bit (or M-valued or multi-valued) [1/2], multi-reader [1/2], multi- writer
[1/2] register

9. Consider the following execution history for an 8-bit, unsigned register depicted below
(a) If you assume that this is a safe register, what will read2() return? (2)
Sol: Any value between 0 and 255 [2] - no marks for ”any value in range” without saying that
the range is 8 bits
(b) If you assume that this is a safe register, what will read1() return? (2)
Sol: 6 [2]
(c) If you assume that this is a regular register, what will read4() return? (2)
Sol: 6 or 3 [2] no part marks both have to be stated

Page 2
(d) If you assume that this is an atomic register, what will read2() return? (2)
Sol: 6 or 3 or 10 [2] no part marks both have to be stated
(e) If you assume that this is an atomic register, what will read3() return? (3)
Sol: 1 mark for saying ”3 or 10” - 2 marks for saying ”if read2 returns 12, then only 12”

10. Consider the following execution history of an atomic SRSW register:

(a) In the implementation of an atomic SRSW register, how can we make sure that read2() does not read an (3)
earlier value than was read by read1()? Justify your answer.
Timestamps [1], Compare with last read value [1] Will use last read value [1]
11. Assuming that a system consists of 10 processors and that 30% of a program can only be executed sequentially. (4)
Using this system, it takes 15 days to execute the program and produce a result. If we can reduce the amount of
work done sequentially to 10% how many days would it take the system to run the program?
Sol: 30% results in 2.7 [1] 10% results 5.26 [1] Answer = (2.27/5.26)*15 = 7.7days [2]
12. What is the difference between multitasking and multiprocessing? (2)
Multitasking simulates the concurrent execution of processes on a single processor [1]. Multi-
processing is the concurrent execution of processes by multiple processors [1].
13. Consider the following lock() method of the Bakery algorithm and answer the question that follows: (4)

public void lock ( ) { //line 1


int i = ThreadID.get() ; //line 2
flag[i] = true ; //line 3
label[i] = max(label[0],...,label[n-1]+1; //line 4
while(flag[k] && (label[k]<label[i]))//for everyk != i
}

What impact has the fourth line of the code have on mutual exclusion.
Mutual exclusion refers to dealing with controlling concurrent access thus when two threads execute
line 4 at the same time [1] they can both end up with the same label [1] and then both continue to
the critical section [1] and we lose mutual exclusion [1]
14. What may be considered as a weakness of the Bakery algorithm and how can it be resolved. (3)
When the maximum value in a variable is reached it may overflow into the smallest value stored
in that variable [1] this makes a late arriving thread acquire a smaller number(ticket) than those
who came earlier. With labels, this would mean that we do not have first-come-first-served fairness
anymore [1]. Timestamps [1] can be used to resolve the overflow problem.
15. Given that the following pseudo-code is used to control access to a critical section. (4)

.
.
\\ code for CS entry

Page 3
wait until flag == 0;
flag = 0;
.
.
\\ code for exiting the CS
flag = flag + 1;
.
.
.

Assuming flag is initialized to 0 would this approach guarantee mutual exclusion in a concurrent environment.
Justify your answer.
Two threads may both find flag = 0 , and both proceed to the second line, and then both set flag
= 0, and then both enter critical section[1]s. When they both exit, they increment flag by 1 , and
the final value of flag is now 1. Any threads wanting to enter the critical section subsequently will
wait at the beginning indefinitely[1], since flag is now 1. One thread [1] may also enter and set the
conditions such that any threads that follow will be unable to enter the CS the approach will only
work once[1]
16. How does an atomic register and a regular register differ with respect to “write order”. (2)
Write order is important to atomic registers as they have multiple writers which then influences
the rule that an earlier read cannot return a value later than that returned by a later read meaning
write order was preserved [1]. Regular registers do not consider write order as they have one
writer[1].

Page 4

You might also like