To deal with deadlocks we can either use prevention or

Assignment Help C/C++ Programming
Reference no: EM13373562

To deal with deadlocks, we can either use prevention, or avoidance, or detection followed by recovery. But which is a better choice in a particular setting where deadlocks could occur from time to time? Let do some "research" to find out the answer. Let's use the classical Dining Philosophers Problem (there are N of them, N ≥ 2) as the case. We will use the naïve, deadlock-prone method (each philosopher first tries to grab the left fork and then the right chopstick) as the base. Thus we should compare:

The naïve method with deadlock avoidance
The naïve method with deadlock detection and recovery
A good method that prevents deadlocks (such as those we mentioned in class)

Since (i) (avoidance) is very similar to (ii) in logic given that the resources (chopsticks) are all single-instance, you are required to implement and compare just (ii) (detection/recovery) and (iii) (prevention). (Well, if you do also (i), we will reward you with some bonus points (≤ 5%).) (iii) should be easy. To implement (ii), you need to figure out WHEN to detect, and the actual detection action; and then of course to resolve the deadlock if indeed one is detected. You might need to add an auxiliary thread to be responsible for all this. For resolving a detected deadlock, you may relax the "no preemption" rule, and ask a philosopher (or more) to release a chopstick that he is holding.

To carry out the comparison using experiments, you need to simulate the thinking/eating cycle of the philosophers, where eating will take E amount of time, and thinking will take T amount of time. E and T should be generated from a statistical distribution (I recommend Gaussian) so that you get some kind of randomness resembling real life. Gaussian distribution is easy to build in C (a few lines will do), and you should be able to find its code from the Internet if you don't want to write it; alternatively, you can use the GSL library where Gaussian is one of a long list of callable random statistical functions. To make a philosopher (represented by a thread) think or eat for T or E amount of time, you can use the sleep() or the finer usleep() function of Linux. If you don't want to bother with using a distribution, you should at least try to generate your Ts and Es using some mean value + a standard deviation (i.e., to draw a random number).

The experiments are to be done on Linux (or Solaris). Please write your code in C or C++, use Pthread to create the threads (one for each philosopher), and use POSIX semaphores (for uniformity) to implement thread synchronization or any critical section that maybe needed. There is a lot of info on using POSIX semaphores in Linux in the Internet, such as this one. If you use C++, the Gaussian distribution is available as part of its random number generation facilities. To repeat running an experiment, you might want to use a shell script. "Make", as always, is also a useful utility, for managing and compiling your source code. If you have to plot any graphs, Matlab is probably the best tool; there are also many open-source graph plotting packages which you can try.

So what will you measure and compare in order to determine the winner or which is better than which (which might depend on the situation)? The CPU Scheduling chapter should give us some insight on this. Throughput (how many philosophers can finish their think/eat cycle within a certain time duration) is definitely an important measure. Perhaps wait time also (you don't want any one to starve or grow grumpy). And maybe fairness. You can use the Linux command "time" to measure the execution time of any of your programs. If you need finer control of the measurements, you could use such functions as clock() inside your code.

You will write an essay to report your experiments and their results, and to present and discuss your findings. More details on the format etc. will be announced subsequently. Other than to answer the question (which is the best method?) for the Dining Philosophers Problem which is a specific case, you may want also to use the results to shed light on how to handle the possibility of deadlock in general when given any situation that might come under the harassment of deadlocks.

Reference no: EM13373562

Questions Cloud

Question 1nbspaccording to the amu plagiarism policy which : question 1nbspaccording to the amu plagiarism policy which of the following are examples of academic dishonestya. using
Question 1nbspworking alone is not considered a : question 1nbspworking alone is not considered a togetherness style only working in groups.truefalsequestion 2nbspwhich
Write 5 sentences about the role of education in successful : write 5 sentences about the role of education in successful financial planing in witch you correctly use a different
Choose a project from your organisation where you do not : choose a project from your organisation. where you do not have a current project either use a project you have worked
To deal with deadlocks we can either use prevention or : to deal with deadlocks we can either use prevention or avoidance or detection followed by recovery. but which is a
Part a consider the information below from a firms balance : part a consider the information below from a firms balance sheet for 2011 and 2012.current assets20122011change cash
1 choose an online newspaper article use the elements of : 1 . choose an online newspaper article. use the elements of reasoning model to analyze the logic of the article. your
Whether or not you ever actually conduct an interview for : whether or not you ever actually conduct an interview for this lesson you need to submit 20 questions to fulfill the
Qestion 1if the velocity potential can be described byphi : question 1if the velocity potential can be described byphi -b4 x-yx ywhere b is some constant what is the formula for

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Use the lengthof the side as a member variable of the class

write a class including four member functions to compute the areas of an equilateral triangle ,square,hexagon and octagon respectively .Use the lengthof the side as a member variable of the class.

  Distinguish syntax and purpose of while-loop and for-loop

Distinguish the syntax and purpose of while-loop and syntax of a for-loop. Give C++ code examples of both loops and descriibe the main differences.

  Write a program to convert between rectangular

Write a program to convert between rectangular and cylindrical coordinates, based upon user input. For example, if the user wants to convert cylindrical to rectangular coordinates, the user would input r, ?, z values and the program would output x, y..

  How nested if-statements replace with one if-statement

Describe how following nested If-statements could be replaced with one if-statement using logical operator (And/Or/Not). Write down the C++ code example.

  The main program should create an ifstream

For decryption, the main program should create an ifstream for the file to be decrypted. It should use the getline method of the ifstream to read lines from the file, call the encryption / decryption function with the line to be decrypted, and dis..

  Write and run a c++ program that computes and displays

A machine purchased for $28,000 is depreciated at a rate of $4,000 a year for 7 years. Write and run a C++ program that computes and displays a depreciation table for 7 years.

  Write in c++ another overloaded operator

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..

  Create a serial object s

The function call operator is overloaded and will generate a sequential integer each time the operator is used and the object can be created with the sequence start value specified.

  Calculate that implements a simple arithmetic calculator

Write a  C program  calc.c that implements a simple arithmetic calculator. Input to the calculator consists of lines composed of integer constants separated by the five arithmetic operators used in C: +, -, *, /, and %. For each line of input,

  Use the convention that all years have 360 days

In writing the days() function, use the convention that all years have 360 days and each month consists of 30 days. The function should return the number of days for any Date structure passed to it. Write a main () function to test your function.

  Calculate distances and map a route

The GPS navigation system uses the graph and geometric algorithms to calculate distances and map a route. One of the geometric problems is the closest-pair problem. Given a set of points, the closest-pair problem is to find the two points that are..

  Calculates the average of three test scores

Write a program that calculates the average of three test scores. The program should contain three value-returning functions: main, getTestScore, and calcAverage

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd