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

  If a class is derived protected

If a class is derived protected from a base class, explain how this affects the inheritance of all public, protected, and private members of the base class by the derived class.

  Write a full program that implements the aggregation concept

Write a full program that implements the aggregation concept for the Mail Message, Header , Body and Attachment classes.

  Write a c++ program which will calculate the monthly balance

Write a C++ program which will calculate the monthly balance of a debt. Each month a payment is made on the balance, and interest is added to the balance using a fixed percentage rate.

  Object-oriented systems is the concept of object

At the heart of all object-oriented systems is the concept of an object. Simply stated, an object is a set of related characteristics and their associated actions.

  Use a for loop to generate 100 random numbers.

Use a For Loop to generate 100 random numbers. Determine the most current maximum and minimum number as the random numbers are being generated. This is referred tp as a "running" maximum and minimum. Display the running maximum and minimum values as ..

  Person class that includes fields for last name

Create a Person class that includes fields for last name, first name, and zip code. Include a default constructor that initializes last name, first name, and zip code to "X" if no arguments are supplied. Also include a display function. Write a ma..

  Individual genes are substrings of a genome

Individual genes are substrings of a genome delineated by 3-element start and stop codons. Genes begin with the start codon ATG and end with one of the following 3 stop codons: TAG, TAA or TGA. Note that start codons can appear anywhere in the string..

  Write two functions to be called by the main program

CSC250 Assignment. Write two functions to be called by the main program. One function is to calculate, in general, a truck's range, that is, the distance the truck can go on one tank of gas (we should probably say fuel. since the bigrig might use ..

  Define a static method samecolor in the car class

Write an abstract class Car to implement the Comparable interface. Write a Truck class and a Sedan class to implement Car. define a static method sameColor in the Car class to find out weather a Truck and a Sedan has the same color.

  Write the code to exchange the values of these two variables

Write the code to exchange the values of these two variables (so that after the swap xp points to what yp originally pointed to and vice-versa.

  Assume that section

Assume that section _1 seats are in front of the stage, and the price is expensive. say, each seat in the 1st three rows is $180.00, and each seat in the last two rows is 10% less;

  Question 1 write a program to print the following patterna

question 1 write a program to print the following patterna 1 b 11 2 2 21 2 3 3 3 31 2 3 4 4 4 4 41 2 3 4 5 5 5 5 5

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