Assignment Concurrent Programming
Assignment Concurrent Programming
Objective:
This assignment has been designed for students to apply appropriate
concurrent program design methods in designing and implementing a
concurrent program from a program specification.
Marking Criteria
The criteria used to evaluate the assignment are as follows:
Usefulness of instructions for compiling and running the program including comment
lines in source codes.
Depth of discussion listing of section(s) that did not meet requirements and/or code
extracts of sections that met requirements.
Level 2
Critical Appraisal
Page 2 of 7
Performance Criteria
1.
A demonstration of your work to the lecturer. Marks will be allocated on the basis of
your ability to deliver a coherent, clear and well-prepared verbal presentation of your
system. To achieve a mark of:
Pass: Your delivery must be clear, but may suffer from a lack of organisation or preparation.
Credit (Lower): As above, plus your presentation is clear, well organised and prepared.
Credit (Upper): as above, plus be able to clearly answer questions from your lecturer about
your system. Your examples cover the majority of the functionality of the system, and are
well chosen to do so.
Distinction: as above, plus the presentation must have an extra spark that makes it stand out
from the other presentations. This mark is reserved for presentations that are of an excellent
standard.
2.
Fail: Your system cannot compile with the command javac *.java.
Credit (Lower): As above, plus the system provided meets all expected functionality.
Distinction: As above, plus the system must have an extra spark that makes it stand out from
other systems. This mark is reserved for systems that have outstanding functionality, and is
free from data corruption and deadlock.
3.
Report on Correctness. This report must provide an argument of how you know that
your system behaves correctly. To receive a mark of:
Fail: Your report cannot be easily read by your lecturer and has many missing parts.
Pass: Your report must be easily read, informally outline the particular concurrency issues
that your system faces and meet satisfactory documentation requirements (seem marking
criteria above).
Credit (Lower): As above, plus you must provide one of a test report or discussion which
shows that your system is free from data corruption and deadlock.
Credit (Upper): As above, plus you must provide discussion that shows that your system is
free from data corruption and deadlock.
Distinction: As above, plus the report must be among the best in the class, and must stand
out from the other reports in your class.
Level 2
Page 3 of 7
MARKING SCHEME
Marks
Criteria
Excellent
Good
Average Poor
Very
Poor
1. Appropriateness
of
coding
techniques used to implement design
(5)
(4)
(3)
(2)
(1/0)
2. Appropriateness
of
the
Java
concurrent programming facilities
used
3. Program runs appropriately
(9-10)
(7-8)
(5-6)
(3-4)
(0-2)
(5)
(4)
(3)
(2)
(1/0)
(5)
(4)
(3)
(2)
(1/0)
SUB-TOTAL (T1)
Excellent
(5)
Good
Average
Poor
(4)
(3)
(2)
SUB-TOTAL (T2)
Level 2
Very
Poor
(1/0)
Page 4 of 7
Case Study
The sleepy salon
The Problem
Standing area
Standing area
Three salon chairs
ENTER
EXIT
Level 2
Page 5 of 7
When the customer first enters the salon, the customer leaves
immediately if more than 20 people are waiting (10 standing and 10
sitting). On the other hand, if the salon is not too full, the customer
enters and waits.
Customers keep track of their order, so the person sitting the longest
is always the next customer to get a haircut.
Deliverables:
For this exercise, you are to model the salon and write a Java program to
simulate activity for this salon:
Simulate each hairdresser and each customer as a separate process.
Altogether, 30 customers should try to enter.
Use a random number generator, so a new customer arrives every 1, 2, 3,
or 4 seconds. (This might be accomplished by an appropriate statement
sleep (1+ (rand () %4)).
Similarly, use a random number generator, so each haircut lasts between 3
and 6 seconds.
Each hairdresser should report when he/she starts each haircut and when
he/she finishes each haircut.
Each customer should report when he/she enters the salon. The customer
also should report if he/she decides to leave immediately.
Similarly, if the customer must stand or sit in the waiting room, the
customer should report when each activity begins.
Finally, the customer should report when the haircut begins and when the
customer finally exits the shop.
Level 2
Page 6 of 7
Sample Output
In order to see what is happening dynamically you must have output from
the Customers and the hairdressers reporting all their major events.
Add information about which process/thread is doing the output. This way
you can see if a process/thread acts for another, which is strictly forbidden,
but is a common error for Java solutions (objects are not processes!). An
example of such incorrect behaviour is
Thread-Hairdresser: 21.31: Hairdresser1: Customer 3 is done!
main: 21.50: Hairdresser: Next customer please!
Thread-Customer-12 : 21.50: Customer12 is waiting for a chair.
Thread-Hairdresser: 21.31: Hairdresser2: Acquiring comb2!
Where you can see that not only the hairdresser thread but also the main
thread is acting for the hairdresser.
Note that realistic time stamps are not required, it is fine to use any function
to generate them.
You must not
Kill a thread or process. You may not use any of the following
primitives in Java:
o
Thread.stop
Thread.resume
Thread.suspend
Thread.interrupt
setDaemon
You may not use the destroy or stop(0) primitives in - except to take
care of temporary resources like simple timers.
If any of those primitives are found in your code, you will fail the
assignment no matter the functionality of it.
Level 2
Page 7 of 7
Tips
Run your program without customers entering the salon. This should
work if your solution is correct. The solutions should not be dependent
on the events created by the customers.
Make very sure of who's actually doing the work. Make this easier for
yourself by printing the name of the process performing an action.
Use short delay times - there is no need for a simulation run to take
more than 20-30 seconds.
Implementation
You should implement your simulation in Java.
Caution!
It might be tempting to use the Thread.interrupt() method to wake sleeping
processes. This is a bad idea. Firstly, we have seen what a mess people can
get into with this! Secondly, a behaviour which is present in every execution
of the program is not exceptional, and is usually considered bad
programming style to use an exception in such cases. In summary, don't use
Thread.interrupt().
Documentation
The documentation should contain the following:
Level 2