UMD CMSC 330 - Sample concurrency questions from past exams (9 pages)

Previewing pages 1, 2, 3 of 9 page document View the full content.
View Full Document

Sample concurrency questions from past exams



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

Sample concurrency questions from past exams

142 views

Problems/Exams


Pages:
9
School:
University of Maryland, College Park
Course:
Cmsc 330 - Organization of Programming Languages
Organization of Programming Languages Documents

Unformatted text preview:

CMSC 330 Sample concurrency questions from past exams Fall 2005 Note these were exam questions from prior semesters of CMSC 330 before Java 1 5 existed therefore all the questions and solutions use Java 1 4 synchronization For additional practice you may also want to consider how the questions or solutions could have been written using Java 1 5 synchronization 1 In this problem you are to modify the concurrent Java program on the next page to ensure that its two threads always take turns in a hypothetical game they are playing The two threads playing the game are player1 a Player1 object and player2 a Player2 object The game consists of turns in which each player makes a move the exact details of the game are not explained The two players are supposed to alternate moves in the game and the game should continue forever Each player thread determines its game move based on the other player s previous move player1 should always make the first move in the game A move in the game is represented using an integer The two threads call methods named decide next move to determine their moves After a thread determines its next move it communicates it to the other thread by calling set move to store it in a shared Move object in the main function of the Game class The other thread can examine that value using get move The function process move is called by each thread to process the other thread s most recent move Note that the code for the classes Player1 and Player2 are almost identical except the statements in their run methods are in different orders This is to cause player1 to make the first move in the game and player2 to initially wait for player1 s first move As the program is currently written the two threads do not use any synchronization so incorrect or inconsistent results may be produced Add appropriate Java synchronization constructs to the program so it always works properly The conditions which must be ensured are Every consecutive move value should be stored and



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Sample concurrency questions from past exams and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Sample concurrency questions from past exams and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?