• No results found

Exam Concurrency & Multithreading VU University Amsterdam, 22 October 2014, 15:15-18:00

N/A
N/A
Protected

Academic year: 2021

Share "Exam Concurrency & Multithreading VU University Amsterdam, 22 October 2014, 15:15-18:00"

Copied!
2
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

Exam Concurrency & Multithreading

VU University Amsterdam, 22 October 2014, 15:15-18:00

(At this exam, you may use the textbook of Herlihy and Shavit. Answers can be given in English or Dutch.

Use of the slides or a laptop is not allowed.)

(The exercises in this exam sum up to 90 points; each student gets 10 points bonus.)

1. Does Peterson’s two-thread mutual exclusion work if we replace the atomic registers flag[0], flag[1] and victim by regular registers? (Explain your answer.)

(10 pts) 2. Why can we in general not define first-come-first-served in a mutual exclusion algo- rithm based on the order in which the first instruction in the lock() method was executed on an atomic register?

Argue your answer in a case-by-case manner, based on the nature of the first in- struction executed by concurrent lock() calls: an atomic read or write, to separate

locations or to the same location. (10 pts)

3. Consider the stack data structure, with the standard push() and pop() methods.

Explain for each of the following three executions, by two threads, whether it is linearizable and/or sequentially consistent. (12 pts)

(a) thread A push(x) push(y)

thread B pop(y) pop(x)

(b) thread A push(x) pop(x)

thread B pop(y) push(y)

(c) thread A push(x) push(y)

thread B pop(x) pop(y)

time axis

4. Suppose that in the 2-thread consensus protocol using a FIFO queue (Figure 5.7 on page 107), a thread first dequeues an element from the queue, and then writes its value in its slot in the proposed array (i.e., lines 13 and 14 are swapped). Would the resulting protocol be wait-free? (Explain your answer.) (8 pts) 5. Consider the following (blocking but lock-free) queue for a single enqueuer and a

single dequeuer.

(2)

class TwoThreadLockFreeQueue<T> { int head, tail;

T[] items;

public TwoThreadLockFreeQueue(int capacity) { head = 0; tail = 0;

items = T[] new Object[capacity]; } public void enq(T x) {

while (tail - head == items.length) {};

items[tail % items.length] = x;

tail++; } public T deq() {

while (tail == head) {};

T x = items[head % items.length];

head++;

return x; } }

Introduce a volatile Boolean variable barrier, and add one or more lines of code where this variable is set to true. Explain why this memory barrier is needed here, and how your adaptation guarantees that the queue works correctly. (12 pts) 6. Adapt the dissemination barrier to make it reusable. (Hint: You may want to keep

track of the sense and parity of the current phase.)

Consider two threads, where one thread is very slow in detecting that it can leave the barrier, while the other thread leaves the barrier and reaches it again. Argue that your reusable dissemination barrier works correctly (also) in this case. (14 pts) 7. Give a (Java pseudocode) implementation of the dequeue method for the unbounded transactional FIFO queue (using atomic blocks). (12 pts) 8. Wall clock time measures the actual elapsed time and includes waiting, while cpu

time only measures the time used to actively process instructions.

In the practical assignment you implemented multiple concurrent data structures and ran measurements using the provided framework. This framework allows you to set a “worktime” parameter: for each add and remove call, some additional (fully parallelizable) work is simulated. This is implemented using wall clock time:

long endTime = System.nanoTime() + workTime;

while (System.nanoTime() < endTime); // busy wait

An alternative approach is to implement this using cpu time:

long endTime = System.nanoTime() + workTime;

while (bean.getCurrentThreadCpuTime() < endTime); // busy wait

Explain which of the two would be the more realistic way of simulating the additional work. How does this influence the results if you are running more threads than there

is parallelism on the machine? (12 pts)

Referenties

GERELATEERDE DOCUMENTEN

We study the cycle time distribution, the waiting times for each customer type, the joint queue length distribution at polling epochs, and the steady-state marginal queue

Het programma is er op gericht om fibromyalgie in uw dagelijks leven een plaats te geven en er zo goed mogelijk mee om te leren gaan.. Voor wie is het

Je legt uit dat je cliënt verschillende keuzes heeft voor zorg en ondersteuning!. Je bespreekt de keuzes die passen bij

Thus, hypertension alone was seen in 32% ofthe patients who developed congestive cardiac failure, whereas the combination of hypertension and myocardial infarction was seen in 43%

The central idea for kernel algorithms within the learning theory context is to change the representation of a data point into a higher-dimensional mapping in a reproducing

(b) Prove that the formula 22p→2p is not valid in the frame (Z, &lt;), the integer numbers ordered by the usual less-than relation &lt;.. System T is the extension of the minimal

(An informal proof suffices.) (5 pt) (b) Draw the first three levels of the tree unravelling (or unfolding) of F 2 taking.. state A as

Give a scenario (including reads and writes to variables) of the CLH lock with timeouts in which initially the lock is free, four threads concurrently want to take the lock, two of