首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
software讲解、辅导program留学生、辅导c/c++语言、C++编程设计调试 辅导Python程序|调试Web开发
IPC and Concurrency
Reminder: The rules of academic conduct apply as described in the course outline. All
coding is to be done individually or in pairs. We will be using software to compare all
assignments handed in by the class to each other, as well as to assignments handed in for
previous terms.
Be sure that this assignment compiles on the Linux computers in the CSIL lab using the
gcc compiler. You can access the Linux server remotely as detailed on the course
discussion forum.
What to Hand In: Include your source code file(s) (.h and .c) and a makefile (with a
default target to make all, and a clean target).
There is a bit of work to do here and you should begin right away. Trust me - you will not
finish this if you leave it for the last week. Do yourself a huge favour and begin NOW.
This is a great assignment. Why is it great you ask? It is great for two reasons:
1. you are going to learn many things:
o how to use UNIX UDP IPC
o increased detail regarding the joy (and pain) of programming concurrent
processes
o how to program using the client/server model
o how to write a multi-threaded program using pthreads (which is
representative of most other threads packages)
o how to solve the critical section problem between threads
2. it is going to be fun
o you are left to judge the truth of this statement
Assignment Overview
For this assignment you are going to create a simple "chat"-like facility that enables
someone at one terminal (or Xterm) to communicate with someone at another terminal.
The interface will not be pretty, but it will be functional.
This program will be called "s-talk" for simple-talk. To initiate an s-talk session two
users will first agree on two things:
o the machine that each will be running on
o the port number (explained later) each will use
Say that Fred and Barney want to talk. Fred is on machine "csil-cpu1" and will use port
number 6060. Barney is on machine "csil-cpu3" and will use port number 6001.
To initiate s-talk, Fred must type:
s-talk 6060 csil-cpu3 6001
And Barney must type:
s-talk 6001 csil-cpu1 6060.
So, (in case you haven't figured it out) the general format is:
s-talk [my port number] [remote machine name] [remote port number]
The result will be that every line typed at each terminal will appear on BOTH terminals:
it will appear character-by-character on the sender’s terminal as they type it, and it will
appear on the receiver’s terminal once the sender presses enter.
If you want to learn about "curses" and "cbreak" on your own, you can alter this slightly
so that every character typed appears on both screens as it is typed rather than having to
wait for each [return]. If you are interested look in the man pages under "curses" (this is
NOT a requirement of the assignment; it is not for marks).
An s-talk session is terminated when either user enters the complete line of text which is
just one ‘!’ and presses enter.
Expected Process Structure for this Assignment
This assignment will be done using pthreads, a kernel-level thread implementation for
LINUX. As you may or may not know, pthreads allows you to create any number of
threads inside one UNIX process. All threads running in the same UNIX process share
memory (which means pointers valid for one thread are valid in another thread) and also
have access to semaphores (mutexes) and the ability to use conditional signal/wait to
synchronize their actions in relation to each other. UNIX itself also allows you to create
multiple processes. Communication between UNIX processes can be done using
something called "datagram sockets" which use a protocol called UDP (universal
datagram protocol).
In this assignment, you will be dealing with processes/threads on two levels. First, you
will have two UNIX processes. Each one is started by one of the people who want to talk
(as a result of executing s-talk). Second, within each s-talk process a pthreads
environment will be running four threads that you will write.
Required threads (in each of the processes):
One of the threads does nothing other than await input from the keyboard.
The other thread does nothing other than await a UDP datagram.
There will also be a thread which prints characters to the screen.
Finally a thread which sends data to the remote UNIX process over the network
using UDP.
All four threads will share access to a list ADT (the one you wrote for assignment #1).
The keyboard input thread, on receipt of input, adds the input to the list of
messages that need to be sent to the remote s-talk client.
The UDP output thread will take each message off this list and send it over the
network to the remote client.
The UDP input thread, on receipt of input from the remote s-talk client, will put
the message onto the list of messages that need to be printed to the local screen.
The screen output thread will take each message off this list and output it to the
screen.
Clearly the lists that are shared between the threads will need to be carefully controlled to
prevent concurrent access. This will be done by using mutexes and signalling/waiting on
condition variables.1
How do you go about starting?
There are several things you are going to have to figure out - and you’d best start NOW! I
think you will appreciate all the knowledge you gain from doing this assignment, but
there is a lot to learn - this is not one you can leave until the last few days. There will be
no extensions.
First, try out some of the keyboard/screen I/O primitives supplied by UNIX without using
pthreads. Check the section 2 man pages under "read", "write" and (optionally) "curses",
"cbreak".
Next (and this is a big one) you'll need to experiment with UNIX UDP sockets. Do this
by experimenting with code that sends a message (without pthreads) from one UNIX
process to another.
Check the man pages for:
socket
bind
sendto
recvfrom
1
It would be easy to modify the process structure to have the keyboard input thread send its characters
directly out over the network, and to have the UDP input thread print its characters directly to the screen.
Please don't do it this way - I'd like you to get more experience writing client/server applications. Plus,
there’s a deduction for doing it the wrong way.
gethostname
gethostbyname
Some of these will be complicated, but don't despair. You can ask the TAs and me
questions in the discussion forum, though we won't answer any questions that can be
easily obtained from the man pages. I also strongly suggest you use the web as a resource
here. Try a search on "UNIX and SOCKET" and see what you come up with. If you find
something good, please share it with others using the discussion forum. There are a
couple of good web-pages that I will point you to:
• Socket programming: http://beej.us/guide/bgnet/
• Pthreads documentation: https://computing.llnl.gov/tutorials/pthreads/
Finally, bring them all together in a pthreads application and two UNIX processes.
Marking
To test, we will not only run your program as a normal user might, but we will also
Pipe a text file to s-talk (contents of the text file appears to your program as
standard keyboard input):
cat someTestData.txt | ./s-talk
o The contents of the someTestData.txt file must be sent over the network to
the attached other s-talk client.
Pipe the output of your program to a text file
./s-talk
>> someOutputData.txt
o The contents of someOutputData.txt must be the data that was sent from
the other s-talk client.
o Your s-talk program may print out additional messages when it starts up,
and/or when it terminates.
We will not intercept or analyze the UDP packets; therefore, you may use
whatever message structure you like in your network packets.
Submit to CourSys a ZIP file of the following:
all your source code (.c and .h files)
a makefile that compiles your .c files and links the objects to any necessary
libraries. The makefile should produce the executable s-talk (all lower case)
which behaves according to the description above. The makefile must have a
default rule to build s-talk, and must also have a ‘clean’ rule.
(optionally) README file documenting any errors, like things you didn’t get
working, or things we need to know to mark your work
Do NOT hand in any executables or .o files.
Have fun and good luck.
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
讲解 econ1202 – quantitativ...
2024-11-22
辅导 msds 490: healthcare an...
2024-11-22
讲解 civl 326 geotechnical d...
2024-11-22
辅导 term paper medicine whe...
2024-11-22
讲解 eng3004 course work辅导...
2024-11-22
讲解 ee512: stochastic proce...
2024-11-22
辅导 geog100 ol01 - fall 202...
2024-11-22
辅导 st5226: spatial statist...
2024-11-22
讲解 ece 101a engineering el...
2024-11-22
讲解 database development an...
2024-11-22
讲解 comp3134 business intel...
2024-11-22
讲解 practice exam 2, math 3...
2024-11-22
讲解 project 4: advanced opt...
2024-11-22
辅导 38003 organisational be...
2024-11-22
辅导 economic growth调试spss
2024-11-22
辅导 ee512: stochastic proce...
2024-11-22
讲解 eesb04 "principles of h...
2024-11-22
辅导 am2060 final assignment...
2024-11-22
辅导 acfim0035 fundamentals ...
2024-11-22
辅导 stat 612 (fall 2024) ho...
2024-11-22
热点标签
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: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!