Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C ONCURRENT & D ISTRIBUTED P ROGRAMMING

(192135300)

F ORMAL M ETHODS & TOOLS GROUP CDP 2011/2012 KW 2

A SSIGNMENT 2 S HARED M EMORY

This second assignment consists of 3 exercises. The maximum number of points for this assignment is 10 points. Consult the website of CDP for the general rules concerning the assignments. The exercises of this assignment should all be answered individually. Remember: always send in your own work no plagiarism! Pen-and-paper exercises can be handed in either in hardcopy by putting them into the mailbox of Marieke Huisman, which can be found in the left hand side of room INF (Zilverling) 5110 or by sending them as a PDF le to M.Huisman@utwente.nl. On the rst page of your solutions you should write your last name, rst name, initials, studentnumber and the name of your study. Modeling exercise in Promela and/or programming exercises have to be submitted by email to M.Huisman@utwente.nl. To do this, make a separate directory (i.e., ex1, ex2, and ex3) for every exercise and put the les related to the exercise in that directory. Each directory should contain a PDF-le (named: report-n.pdf) where n is the number of the exercise which contains the report as discussed below. The rst page of each report should contain your last name, rst name, initials and studentnumber and the name of your study. In the exercises you are asked to model a system or protocol and prove that the model is (in)correct. A solution, however, is more than the model and the output of the model checker alone. You are expected to write a short but clear report on your solutions (in English or Dutch). This means that you should provide comments on all your models, specications, properties, verication results, etc. Clearly explain how you have solved the exercises. It should be clear from your report that you knew what you were doing. The deadline for the solutions to this assignment is Tuesday, January 10, 2012 23:59h.

Exercise 1

(3 points)

Two global integer variables are declared: x and y. The variable x is initialized to ten, and the variable y is initialized to zero. Two parallel threads execute the following statements, respectively (given in [Ben-Ari 2006]-like pseudo-code): Thread 1: while (x != y) { x = x - 1; y = y + 1; } Thread 2: await (x == y); atomically { x = 8; y = 2; } Write a P ROMELA model that captures the behaviour of this system and answer the following questions. (a) Use S PIN to check if both threads always terminate, and to show what the nal values of x and y can be upon termination. (b) Explain what happens if the assignments to x and y in Thread 2 are not executed atomically and conrm your explanation with S PIN.

A B C

r.read(1) r.write(1) r.write(2)


Figure 1: First history for Exercise 2.

r.read(2)

A B C

r.read(1) r.write(1) r.write(2)


Figure 2: Second history for Exercise 2.

r.read(1)

Exercise 2

(3 points)

(a) Give an example of an execution that is quiescently consistent but not sequentially consistent, and another that is sequentially consistent but not quiescently consistent. (b) For each of the histories shown in Figs. 1 and 2, are they quiescently consistent? Sequentially consistent? Linearizable? Justify your answer.

Exercise 3

(4 points)

Design a bounded lock-based Stack<T> using an array. (a) Use a single lock and a bounded array. (b) Try to make your algorithm lock-free. Where do you run into difculty?

[CDP 2011/2012 kw2 13 December 2011]

You might also like