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

  Create a template class

Create a template class, SVector, that implements a constructor

  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 c program which has parent process and child process

Write a C program that has a parent process, a child process, and a grandchild process. The parent process should print its id and the square or 5.

  Create a program that maintains the required book catalog

Create a program that maintains the required book catalog for the circulation desk of a library.

  Describe the probability of the moves

Write a program in C++ to describe the Probability of the moves

  Design and write a c++11/fltk game program

The project is to design and write a C++11/FLTK game program with a graphical user interface. The game is based on "pancake sorting," which actually has some mathematical significance.

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  Time conversion

Write a C++ program that takes an Eastern standard time in hours, minutes, and seconds,and prints it out in Central time, Mountain time, or Pacific time.

  Write and test c program which outputs waveform

Write and test a C program which outputs waveform which switches from 10.0 kHz with a 50% duty cycle to 25.0 kHz with a 5% duty cycle every 5 seconds.

  Computer programming techniques

Construct a program from a design and use appropriate functions

  Design for storing the maze layout

Design and implement a C++ program for maze layout

  Illustrate example from ansi c programming language

Illustrate example from ANSI C programming language, without using nested procedures, to show the fact that "assignment-by-sharing in conjunction with quasi-dynamic object binding

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