View the step-by-step solution to:

Summer 2005-2006 CS 381 Assignment 2 - IPC and Threads Due Date: You may consult with other students about: o USE of compiler, debugger or general C...

There are N players (numbered 0 to N-1) that sit in a circle and play the following game.
The first person (player 0) starts with a token of initial value Tok_value. If the value
of the token is not 0 it decrements the value of token by one and passes it to the next
person (player 1). The receiver (player 1) checks if the token is 0 or not, if not the
Summer 2005-2006 CS 381 Assignment 2 – IPC and Threads Due Date: Sunday, July 02, 2006 @ 10 pm This assignment is to be done individually. Here are some rules regarding the assignments in this course: You may consult with other students about: o USE of compiler, debugger or general C programming issues. o UNIX shell user-commands. You can't get help from others for fixing errors in your program or for solving the assignment. For any other questions about the assignment please consult with the TA or the instructor. Rules regarding late submission of assignments are on the course website. Policies regarding plagiarism are in the Student Handbook. General Instructions: The purpose of this assignment is to give you practice in the use of inter-process communication (IPC) primitives and threads. It has two parts which are detailed in the following sections. Important: Make a directory called cs381a2 in your home directory where you will place your code for this assignment. Turn off access permissions to this directory so that other users cannot read your code. I.e. do the following: mkdir cs381a2 chmod go-rwx cs381a2 Failure to turn off the access permissions will be seen as an attempt to help others cheat and will result in zero marks in your assignment. PART I: IPC Marks: 50 In this part you will implement the following problem using UNIX pipes and signals. There are N players (numbered 0 to N-1 ) that sit in a circle and play the following game. The first person (player 0) starts with a token of initial value Tok_value. If the value of the token is not 0 it decrements the value of token by one and passes it to the next person (player 1). The receiver (player 1) checks if the token is 0 or not, if not the
Background image of page 1
Summer 2005-2006 receiver just decrements the value of the token by one and passes it to the next person (player 2) and so-on. Otherwise, if the value of token was zero the receiver collects a point and passes a new token with initial value of Tok_value to the next player. The first player to collect Pt points wins and then kills all the others. For example: If N = 9, Tok_value = 4 and Pt = 2 , the players are numbered 0 to 8. Player 4 gets the first point then player 0 gains a point and so on. In this example players gain points in the following order 4, 0, 5, 1, 6, 2, 7, 3, 8, 4 and 4 wins because it is the first one to get Pt=2 points. Write a program to simulate the above game. You program should get the inputs N, Tok_value and Pt from the user. It then spawns N processes and then links the last process to the first. The linking is being done through unnamed pipes (i.e. there should be a pipe between two consecutive persons). The ith process represents the ith person in the circle. Note that the first process has to generate two pipes, one to communicate with the second process and one with the last process. The token is passed using UNIX unnamed pipes. The winner kills the losers by sending the signal SIGTERM along the circle. (Refer to kill() system call for this). Before each loser is killed, he has to close the pipes which he uses (i.e., you have to write a signal handler for SIGTERM). You must output the progress of the game. E.g. when a receiver gets a token it prints something like the following: - I am player number <X>. I have received a token with value <Y> and I am now sending token to player <Z>. My current points are <W>. If a player wins it prints: I am player number <X>. I have <Y> points. I have won!!! Each player that is killed prints before exiting: I am player number <X>. I have been killed. PART II: THREADS Marks: 50 In this part you will implement the following problem using Pthreads. Given two matrices A and B, where A is a matrix with M rows and K columns and matrix B contains K rows and N columns, the matrix product of A and B is matrix C, where C contains M rows and N columns. The entry in matrix C for row i , column j , ( C i,j ) is the sum of products of the elements for row i in matrix A and column j in matrix B. In this part you will calculate each element C i,j in a separate worker thread. This will involve creating MxN worker threads. The main or parent thread will initialize the matrices A and B and allocate sufficient memory for matrix C, which will hold the product of matrices A and B. These matrices will be declared as global data and every thread will have access to A, B and C. The matrices will be populated by reading in values from a file. For example, the first two lines of the file will have the number of rows and column values respectively followed by the matrix data.
Background image of page 2
Show entire document

This question was asked on Mar 17, 2010.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors and customizable flashcards—available anywhere, anytime.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access or to earn money with our Marketplace.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
  • -

    Flashcards

    Browse existing sets or create your own using our digital flashcard system. A simple yet effective studying tool to help you earn the grade that you want!

    Browse Flashcards