# Midsol - CS 3211 1 NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING Solution to Midterm EXAMINATION FOR Semester 2 2009/2010 CS 3211 PARALLEL

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 3211 1 NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING Solution to Midterm EXAMINATION FOR Semester 2, 2009/2010 CS 3211 - PARALLEL and CONCURRENT PROGRAMMING March 2010 Time Allowed: 1 Hour 15 minutes A. Define a process Duplicate which takes a value 0..9 as input, and outputs two copies of the value. Use process equations to define the process. [2 marks] Answer: Duplicate = in(x:0..9) -> ( out1(x) || out2(x) ) -> Duplicate. or Duplicate = in(x:0..9) -> out1(x) -> out2(x) -> Duplicate. CS 3211 2 B. Consider a lock process defined via a process equation Lock = acquire -> release -> Lock. Processes using the lock will synchronize with it using the acquire and release actions. Extend the above definition to define a lock process which can be acquired by the same process more than once, just like the recursive locking mechanism in Java which was taught in class. [2 marks] Answer: Jlock(0) = acquire -> Jlock(1). Jlock(x) = (acquire -> Jlock(x+1)) | (release -> Jlock(x-1)). where x > 0 There is no bound on the number of times the lock may be acquired but the number of non-released acquisitions are kept track of. CS 3211 3 C. Consider an asynchronous composition of two processes described in the Promela modeling language. byte x; proctype myproc(bool i) { do :: x = x + x; od } init{ atomic{ run myproc(0); run myproc(1) } } Use the semantics of Promela to find out the values taken by x during the program execution. Initially x is equal to 1. [2 marks] Answer: Every execution of the loop duplicates the value of x . So, x will assume the values of the form 2 n for n ≥ 0. CS 3211 4 D. Suppose the infinite loop in Question C is compiled into the following assembly code. The processes are running asynchronously, and each time a process is scheduled, only its next instruction is executed atomically. Initially x = 1, and we use a hypothetical machine with infinite memory. Note thatatomically....
View Full Document

## This note was uploaded on 12/02/2011 for the course CS 3211 taught by Professor Dunnowho during the Spring '11 term at National University of Singapore.

### Page1 / 9

Midsol - CS 3211 1 NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING Solution to Midterm EXAMINATION FOR Semester 2 2009/2010 CS 3211 PARALLEL

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online