Native method with deadlock detection and recovery

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

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: EM13120877

Questions Cloud

Show support for the bond payable discount by preparing : On June 1, 2002, a company purchased on the open market $20,000 of a company's non-convertible (or convertible) bonds (2% of $1,000,000 bonds outstanding) at a price of "60" ($12,000 cash) plus accrued interest.
Logarithms and depreciation method : Suppose a machine is worth 33000 after 4 years and 18000 after 8. Find the rate of depreciation using the linear depreciation method
What is the percent yield for the reaction : A 24.0 g sample of nitrogen gas reacts with an excess of hydrogen gas to give an actual yield of 3.85 g NH3. What is the percent yield for this reaction? Reaction: N2(g) + 3 H2(g) ? 2 NH3(g)
Stock holders equity section of the balance sheet : Moran corporation has these accounts at December 31:common stock,$12 par, 5150 shares issued,$61,800;paid in,capital in excess of par value $20,100, retained earning $42,360, and treasury stock-common, 510 share,$12,240. Prepare the stock holders ..
Native method with deadlock detection and recovery : The naïve method with deadlock avoidance and the naïve method with deadlock detection and recovery - what will you measure and compare in order to determine the winner or which is better
Find out the ordering-holding and total inventory costs : It costs approximately $20 to place an order the supplier currently order 100 batteries per month. Find out the ordering, holding, and total inventory costs for the current order quantity
Which student measures the larger density : Two students measure the density of gold. One works with a 100-g bar of pure gold. The other works with a 200-g bar of pure gold. Which student measures the larger density.
Determining equations from word problems : For 1989 and 1990 Dave Johnson had the highest decathlon score in the world. When Johnson reached a speed of 32 ft/sec on the pole vault runway, his height above the ground t seconds after leaving the ground was given by h= -16t^2+32t.
Gain or loss-basis in new property : Determine Debbie's and Elizabeth's realized gain or loss, recognized gain or loss, and the basis in their new property.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Method celsius return celsius equivalent of fahrenheit

Method Celsius return the Celsius equivalent of a Fahrenheit temperature,using the calculation Celsius = 5.0/9.0*(Fahrenheit -32); method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation  Fahrenheit = 9.0/5..

  A constructor and a destructor

A constructor and a destructor, Insert a new element chosen by the user at the correct place in the list

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  Lu decomposition with gauss elimination

The LU decomposition with Gauss elimination and what is the physical interpretation of the elements of ? Write C++ programs for steps 2, 3, and 4.

  Write program which inputs number of winning coupons

Write a program which inputs number of coupons you win and outputs how many candy bars and gumballs you can get if you spend all off your coupons on candy bars first and remaining coupons on gumballs in c++.

  Program to produce ten random permutations of numbers

In C++(must be able to compile in Visual Studio ): Write a program to produce ten random permutations of numbers 1 to 10.

  Program to add numbers and display sum

For each of problems write C++ code to do the required task. Receive the number and find out whether it is odd or even.

  You will create a linked list module

You will create a linked list module that exactly meets the specifications given in the supplied header (.h) file. The playlist program must accept a filename on the command line (argv).

  Draws a single level for a "rogue­like" computer game

You will write a program that draws a single level for a "Rogue­like" computer game. The program will parse a line of input text from an input file (room.txt), use the parsed text to determine the shape of the room and its contents and then draw the ..

  Write a program that will be used to gather statistical data

Write a program that will be used to gather statistical data about the number of movies

  Write program which prompts user to enter numbers

Write down the program which prompts the user to enter numbers, findsout how many positive and negative values have been entered, and calculates sum and average of numbers entered.

  Write application to calculate price of carpeting for room

The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms.

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