首页
编程语言
数据库
网络开发
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
热点文章
更多
辅导 cs1b spring 2024 tth hw...
2024-04-19
讲解 managing financial risk...
2024-04-19
辅导 cs 0449 – project 5: /...
2024-04-19
辅导 elec 2141 digital circu...
2024-04-19
讲解 csc171 — videogame pro...
2024-04-19
讲解 comp3411 artificial int...
2024-04-19
讲解 stat3061: random proces...
2024-04-19
辅导 accounting 452, spring ...
2024-04-19
辅导 finc5001 foundations in...
2024-04-19
辅导 7ssmm712 – topics in a...
2024-04-19
讲解 com 337 - film studies ...
2024-04-19
辅导 mes202tc - digital vlsi...
2024-04-19
辅导 geography 2041b distanc...
2024-04-19
辅导 ecos3006 international ...
2024-04-19
讲解 fit5225 2024 sm1 creati...
2024-04-19
讲解 cit 593: introduction t...
2024-04-19
讲解 math 4931: take home ex...
2024-04-19
辅导 csci 547|info 533: syst...
2024-04-19
辅导 cs536-s24 intro to pls ...
2024-04-19
讲解 fit5212 - assignment 1辅...
2024-04-19
热点标签
ee5311
imse2113
comp 2322
acct2102
fnd109
int102
is3s664
is6153
data4000
accfin5034
fit5212
cs536-s24
fit5225
ecos3006
mes202tc
finc5001
stat3061
csc171
cs1b
7ssmm712
cpt206
swen90004
cs170
comp3411
bu.450.760
comp5313/comp4313—large
bl5611
kxo206
comp532
elec207
kxo151
hpm 573
dts101tc
cs 2820
cpt108
math2319
dts204tc
qm222
comp2511
ccs599
infs1001
mat2355
eeee4123
25721
ifn647
pols0010
cs 2550
cse340
comp2003j
comp9417
qbus6860
stat0023
csci 1100
cs 61b
cs360
fin 3080
ierg 4080
cs6238
cit 594
finm7406
hw6
elec9713
asb-2522
lit301
mcd4540
geog0030
125.330
biol0006
125.320
cs3334
fit2093
acct1101
110.309
masy1-gc
cs314
elec0048
gds104
mg5637
math5905
fit2096
07
mso3610
eel4837
sehs4515
cpt s 321
asb2522 investment
ma214
co2104
mgmt2015
32516
math32051
econ1012
mark2052
dsci 525
comp3310
econ0019
comp30023
abmf3184
aps106
antc27
finm7401
itp122
tech2300
math3026
cs 211
36318
cao107
fit1047
is2022
comp9024
ics4u
2xc3
en.540.635
4qqmn506
finn3081
phys10362
sta601
ec481e
math5165
csi 2120
el1205
comp7250
ecos3013
beam065
info1113
sehh2042
comp2051
csc325
mne 6130
ai6126
inu1111
ecs150
is61x6
cse115
seng6110
bus265
cpts260
mphy0009
csc306
eco2011
ee3004
st332
idepg001
info6001
cpt106
qbus2820
fins5516
finm7409
fit3152
isom3028
eece 6083
ceg5304
mcd4700
eecs 493
eg25h4
38173
elc5216
infs6071
lubs5996m
7ssmm803
glbh0031
phys1120
comp52715
eeb240
soci3403
math3836
cmns3490
iy5610/4610
cpt304
ac6105
psyc3241
fin570
218.323
lng310
rim3352
bio206
comp3334
ac.f633
asb-3525
cs 1501
cpt408
bust10134
lng206
acfi302
soc100
infr11199
csc1002
comp9334
csci 2122
etf5650
eco202y1y
acct608
apm236
gbsh0007
efim20005
actl5105
elec 292
sdsc4026
ds2500
dts205tc
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!