SYSC 3303 H

11 Pages
181 Views
Unlock Document

Department
Systems and Computer Engineering
Course
SYSC 3303
Professor
All Professors
Semester
Fall

Description
Carleton University Department of Systems and Computer Engineering SYSC 3303A RealTime Concurrent Systems Summer 2010 Midterm Exam thMonday July 26Sample Solutions This exam is 1 hour 15 minutes 75 min longThere are 5 questions worth 80 marksThe last page of the exam is the Box class studied in the lecturesYou may remove this page from the exam if you wish demonstrate your understanding of the material coveredItsEnsure that your answers fullybetter to say too much than not enoughAnswer all the questions in the space providedNote that lots of extra space has been provided especially on the programming questions so dont panic if you dont use it all You may use the back of each page for rough workIf you continue an answer on the back of a page indicate that clearly on the front of a page and circle what should be marked Do not ask questions during the exam unless you believe that you have found an errorIf you think something is unclear or ambiguous make a reasonable assumption write it down and then answer the questionQuestion 1 15 marks 5 each partIn this question you are going to add some new methods to the Box class given on the last page of this examAs mentioned above you may remove the last page from the exama Write method setContentssetContents has one argument an Object and does not return anything ie its a void methodRegardless of the current Box state ie whether it is empty or not this method sets the contents of the Box to the Object argumentb Write method updateWhenFullupdateWhenFull has one argument an Object and does not return anythingIt is similar to method setContents above but it may only proceed if the Box is not emptyIn other words when the Box is full it replaces the contents with the Object argumentc Write method getContentsgetContents has no arguments and returns an ObjectIf the Box is empty it returns null otherwise it returns the contents of the BoxSpace is provided on the next two pages for your answersClearly identify parts a b and c of your answersEnsure that you provide sufficient internal synchronization for your additional Box methods to work properly in a multithreaded environmentPage 1 of 11 asetContents has one argument an Object and does not returnanything ie its a void methodRegardless of thecurrent Box state ie whether it is empty or not thismethod sets the contents of the Box to the Object argument public synchronized void setContentsObject item no need to wait as we do the same thing if box empty or full set the contents contentsitemif box was empty change status and notifyAllIf the box is already full changing status and especially notifying is a waste if emptyemptyfalsenotifyAllbupdateWhenFull has one argument an Object and does notreturn anythingIt is similar to method setContents above but it may only proceed if the Box is not emptyIn other words when the Box is full it replaces the contents with the Object argument public synchronized void updateWhenFullObject item wait until the box is full while emptytrywaitcatch InterruptedException e returnupdate the contents contentsitem empty is already false so it doesnt change andno notification required Page 2 of 11
More Less

Related notes for SYSC 3303

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit