首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
Programming编程语言讲解、java程序辅导 讲解数据库SQL|辅导R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
Concurrent Programming
COMP 409, Winter 2021
Assignment 2
Due date: Tuesday, February 23, 2021
6pm
General Requirements
These instructions require you use Java. All code should be well-commented, in a professional style, with appropriate
variables names, indenting, etc. Your code must be clear and readable. Marks will be very generously
deducted for bad style or lack of clarity.
There must be no data races: all shared variable access must be properly protected by synchronization.
Any variable that is written by one thread and read or written by another should only be accessed within a
synchronized block (protected by the same lock), or marked as volatile. At the same time, avoid unnecessary
use of synchronization or use of volatile. Unless otherwise specified, your programs should aim to be efficient,
and exhibit high parallelism, maximizing the ability of threads to execute concurrently. Please stick closely to
the described input and output formats.
Your assignment submission must include a separate text file, declaration.txt stating “This assignment
solution represents my own efforts, and was designed and written entirely by me”. Assignments without this
declaration, or for which this assertion is found to be untrue are not accepted. In the latter case it will also be
referred to the academic integrity office.
Questions
1. Suppose you use multiple threads to move checker pieces around an 8 × 8 checkerboard. To avoid 15
conflicts, each individual square is protected by an associated lock, using blocking synchronization to
ensure that the contents of that square can only be modified by one thread at a time.
A checker in this simulation can move either by sliding to an empty square diagonally adjacent, or by
capturing other checkers, which it does by jumping diagonally over an adjacent checker, provided the
square it jumps over is occupied and the square it jumps to is empty. Note that this is a single-player
simulation that only models the movement/capturing mechanics of the actual checkers game—there is
only one kind of checker (no colours, no kings), and movement can be in any direction.
Build a multi-threaded simulation of this. First, populate the board with 2 ≤ t < 32 checkers at random
locations, all on the same colour square, and not overlapping. Then launch t threads, each controlling
one of the checkers.
Each thread sleeps for m milliseconds and then attempts to move its checker in one of the 4 diagonal
directions, either a simple (if the square is unoccupied), or capturing (if possible). The direction should
be randomly chosen, but you may need to check more than one direction if a move is not possible (if no
move is possible after checking the 4 diagonals then just wait sleep and try again).
Both the capturing and moving actions need to guarantee the state of any affected squares in a given
diagonal direction is not changed by other threads/checkers while it tries to move by ensuring exclusive
accesss to each relevant square. Threads that do not conflict must, however, be able to move concurrently.
If a checker is captured, the thread managing that checker waits 2m–4m milliseconds, and then repeatedly
tests random squares (of the same original colour) to find and place its checker back on the board, while
avoiding any potential overlap. After successfully moving or being captured or replacing its checker on
the board, a thread prints out to the console a message, formatted like:
1
Tx: moves to (x,y)
Tx: captures (x,y)
Tx: captured
Tx: respawning at (x,y)
Where x is a thread id, and coordinates are based on the origin (0, 0) in the bottom-left corner. Note that
you must only using blocking synchronization (monitors, locks, semaphores)—all attempts to acquire a
lock must proceed until the operation succeeds—no spinning!
Provide a Java program checkers.java that takes three integer command-line parameters t, k, and
n, where n is a count of the number of moves to be made by thread; once a thread has made n moves
or captures, it exits. Your solution should allow for maximal concurrency—operations should not be
serialized unless necessary. Your program should work correctly and terminate for all reasonable values/combinations
of parameters, but to test it choose a small value for k, let t = 16, and let the simulation
run for n ≥ 200.
Include a sample of the resulting output with your submission, along with a text file deadlock.txt
which briefly explains how you guarantee your program does not deadlock.
2. A break-out room is created as a space shared by students within the faculties of Arts, Science, and
Engineering. Students in each faculty may use the room, individually deciding whether to enter or leave
once inside, but at any given time all the students in the room must be from the same faculty, so if the
room is occupied by one faculty’s students then students from other faculties have to wait outside until it
is free. It is also important that the room be fairly shared; no faculty’s students should be starved from
entering the room.
Model this using 12 threads, with 4 threads per faculty. Each thread repeatedly sleeps for k–10k milliseconds
(time randomly chosen) and then attempts to enter the room. Once in the room, the thread sleeps
for a random time, w–10w milliseconds, and then leaves and repeats its cycle.
Choose reasonable k and w to ensure high room competition and let the simulation run for n seconds,
keeping track of which faculty (or empty) is currently occupying the room at each point in time: each
time the room “ownership” changes, print out the faculty name or empty to the console (each time on
a separate line). After n seconds the simulation should gracefully terminate. Include a sample of the
resulting output with your submission.
Use only blocking synchronization. Your solution should accept 3 command-line parameters, n, k, and
w. Provide two solutions:
• A version called “breakoutMon.java” using monitors for synchronization. 10
• A version called “breakoutSem.java” using semaphores for synchronization. 10
What to hand in
Submit your declaration and assignment files to MyCourses. Note that clock accuracy varies, and late assignments
will not be accepted without a medical note: do not wait until the last minute. Assignments must be
submitted on the due date before 6pm.
Where possible hand in only source code files containing code you write. Do not submit compiled binaries or
.class files. For any written answer questions, submit either an ASCII text document or a .pdf file. Avoid .doc
or .docx files. Images (plots or scans) are acceptable in all common graphic file formats.
This assignment is worth 15% of your final grade. 35
2
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写infosys 110 digital syst...
2024-12-28
代写fbe 506 quantitative met...
2024-12-28
代做part i: (crazy eddie htm...
2024-12-28
代写infosys 110 digital syst...
2024-12-28
代做stats 769 statistics sec...
2024-12-28
代写ece3700j introduction to...
2024-12-28
代做tcm2301 biochemistry代做...
2024-12-28
代做ece5550: applied kalman ...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写scicomp project 3 week 4...
2024-12-28
代做business operations anal...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写socs0100 computational t...
2024-12-28
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!