CS3211-Tut5 - CS3211 Parallel and Concurrent Programming...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS3211 Parallel and Concurrent Programming – Guidelines for tutorial (1-5 March 2010) Sample Exercises: [Please conduct these as an interactive discussion, rather than an evaluation. Please also make it clear to the students that they are not being evaluated for their performance in these exercises, so that they are not afraid to make mistakes while answering.] 1. A single-slot buffer may be modeled by ONEBUF = (put -> get -> ONEBUF) Program a Java class, OneBuf, that implements this one-slot buffer as a monitor. public class OneBuf { private int buf ; private boolean empty = true ; public synchronized void put( int x) throws InterruptedException{ while (! empty ) wait(); buf = x; empty = false ; notifyAll(); } public synchronized int get() throws InterruptedException{ while ( empty ) wait(); empty = true ; notifyAll(); return buf ; } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. A museum allows visitors to enter through the east entrance and leave through its west exit. Arrivals and departures are signaled to the museum controller by the turnstiles at the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 3

CS3211-Tut5 - CS3211 Parallel and Concurrent Programming...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online