” IPC and Concurrency课程程序 写作、 辅导program留学生程序IPC and ConcurrencyReminder: The rules of academic conduct apply as described in the course outline. Allcoding is to be done individually or in pairs. We will be using software to compare allassignments handed in by the class to each other, as well as to assignments handed in forprevious terms.Be sure that this assignment compiles on the Linux computers in the CSIL lab using thegcc compiler. You can access the Linux server remotely as detailed on the coursediscussion forum.What to Hand In: Include your source code file(s) (.h and .c) and a makefile (with adefault 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 notfinish 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 IPCo increased detail regarding the joy (and pain) of programming concurrentprocesseso how to program using the client/server modelo how to write a multi-threaded program using pthreads (which isrepresentative of most other threads packages)o how to solve the critical section problem between threads2. it is going to be funo you are left to judge the truth of this statementAssignment Overviewsoftware课程作业 写作、 辅导program留学生作业For this assignment you are going to create a simple chat-like facility that enablessomeone 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 twousers will first agree on two things:o the machine that each will be running ono the port number (explained later) each will useSay that Fred and Barney want to talk. Fred is on machine csil-cpu1 and will use portnumber 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 6001And Barney must type:s-talk 6001 csil-cpu1 6060.So, (in case you havent 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 senders terminal as they type it, and it willappear on the receivers terminal once the sender presses enter.If you want to learn about curses and cbreak on your own, you can alter this slightlyso that every character typed appears on both screens as it is typed rather than having towait for each [return]. If you are interested look in the man pages under curses (this isNOT 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 isjust one ! and presses enter.Expected Process Structure for this AssignmentThis assignment will be done using pthreads, a kernel-level thread implementation forLINUX. As you may or may not know, pthreads allows you to create any number ofthreads inside one UNIX process. All threads running in the same UNIX process sharememory (which means pointers valid for one thread are valid in another thread) and alsohave access to semaphores (mutexes) and the ability to use conditional signal/wait tosynchronize their actions in relation to each other. UNIX itself also allows you to createmultiple processes. Communication between UNIX processes can be done usingsomething called datagram sockets which use a protocol called UDP (universaldatagram protocol).In this assignment, you will be dealing with processes/threads on two levels. First, youwill 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 pthreadsenvironment 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 networkusing 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 ofmessages 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 thenetwork to the remote client. The UDP input thread, on receipt of input from the remote s-talk client, will putthe 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 thescreen.Clearly the lists that are shared between the threads will need to be carefully controlled toprevent concurrent access. This will be done by using mutexes and signalling/waiting oncondition variables.1How do you go about starting?There are several things you are going to have to figure out – and youd best start NOW! Ithink you will appreciate all the knowledge you gain from doing this assignment, butthere is a lot to learn – this is not one you can leave until the last few days. There will beno extensions.First, try out some of the keyboard/screen I/O primitives supplied by UNIX without usingpthreads. Check the section 2 man pages under read, write and (optionally) curses,cbreak.Next (and this is a big one) youll need to experiment with UNIX UDP sockets. Do thisby experimenting with code that sends a message (without pthreads) from one UNIXprocess to another.Check the man pages for: socket bind sendto recvfrom1It would be easy to modify the process structure to have the keyboard input thread send its charactersdirectly out over the network, and to have the UDP input thread print its characters directly to the screen.Please dont do it this way – Id like you to get more experience writing client/server applications. Plus,theres a deduction for doing it the wrong way. gethostname gethostbynameSome of these will be complicated, but dont despair. You can ask the TAs and mequestions in the discussion forum, though we wont answer any questions that can beeasily obtained from the man pages. I also strongly suggest you use the web as a resourcehere. Try a search on UNIX and SOCKET and see what you come up with. If you findsomething good, please share it with others using the discussion forum. There are acouple of good web-pages that I will point you to: Socket programming: https://beej.us/guide/bgnet/ Pthreads documentation: httpss://computing.llnl.gov/tutorials/pthreads/Finally, bring them all together in a pthreads application and two UNIX processes.MarkingTo 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 asstandard keyboard input):cat sSomeTestData.txt | ./s-talk args go hereo The contents of the SomeTestData.txt file must be sent over the network tothe attached other S-talk client. Pipe the output of your program to a text file./s-talk args go here someOutputData.txto The contents of someOutputData.txt must be the data that was sent fromthe 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 usewhatever 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 necessarylibraries. The makefile should produce the executable s-talk (all lower case)which behaves according to the description above. The makefile must have adefault rule to build s-talk, and Must also have a clean rule. (optionally) README file documenting any errors, like things you didnt getworking, 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
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。