3. An implementation of two functions is shown below, one is called inside fork() when creating...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. An implementation of two functions is shown below, one is called inside fork() when creating a new process and the other one is called inside exit() when exiting a process. #define CAPACITY 511 int num_procs - 0; /* inside fork () this function is called */ int assign_proc () { int pid; if (num_proc3 САРАCITY) == return -13; else { /* assign resources to th: process */ num_procs++; return pid; /* inside exit () this function is called void free_proc () { /* free up the resources of this process */ num_procs--: (a) Is there a race condition or race conditions here? Where and why? (b) Suppose there is a lock called lock that's used to provide mutual exclusion and associated with it are the functions acquire () and release (). Where do we need to put them to eliminate the race condition(s)? (c) Recall that an atomic integer in Linux is an integer which have associated math operations that are performed atomically or without interruption, e.g.: atomic_t counter; atomic_inc (&counter); /* counter++: */ atomic_dec (6counter); /* counter--; */ These operations are all atomic, acting on the atomic integer counter. If we change int num_procs = 0; to an atomic integer atomic_t num_procs = 0; Also change the increment of num_procs to atomic_inc () and decrement of num_procs to atomic_dec (). Does this solve the problem of race conditions? 3. An implementation of two functions is shown below, one is called inside fork() when creating a new process and the other one is called inside exit() when exiting a process. #define CAPACITY 511 int num_procs - 0; /* inside fork () this function is called */ int assign_proc () { int pid; if (num_proc3 САРАCITY) == return -13; else { /* assign resources to th: process */ num_procs++; return pid; /* inside exit () this function is called void free_proc () { /* free up the resources of this process */ num_procs--: (a) Is there a race condition or race conditions here? Where and why? (b) Suppose there is a lock called lock that's used to provide mutual exclusion and associated with it are the functions acquire () and release (). Where do we need to put them to eliminate the race condition(s)? (c) Recall that an atomic integer in Linux is an integer which have associated math operations that are performed atomically or without interruption, e.g.: atomic_t counter; atomic_inc (&counter); /* counter++: */ atomic_dec (6counter); /* counter--; */ These operations are all atomic, acting on the atomic integer counter. If we change int num_procs = 0; to an atomic integer atomic_t num_procs = 0; Also change the increment of num_procs to atomic_inc () and decrement of num_procs to atomic_dec (). Does this solve the problem of race conditions?
Expert Answer:
Answer rating: 100% (QA)
define CAPACITY 511 int numprocs0 inside fork this funciton is called int assignproc int pid ifnumpr... View the full answer
Related Book For
Differential Equations and Linear Algebra
ISBN: 978-0131860612
2nd edition
Authors: Jerry Farlow, James E. Hall, Jean Marie McDill, Beverly H. West
Posted Date:
Students also viewed these programming questions
-
= 25.1 Find the conditional factor demand for factor if the firm wants to produce y units of output with the production function f(x, x) = min (0.5x1, 0.3x2). Price of output p = 39.1 and prices of...
-
Why is it difficult to implement mutual exclusion and condition variables in an environment? Where like CPUs do not share any memory? What approach and mechanism could be used to make such features...
-
Why is some trade credit called free while other credit is called costly? If a firm buys on terms of 2/10, net 30, pays at the end of the 30th day, and typically shows $300,000 of accounts payable on...
-
Kyoko is a hard-working college sophomore. One Thursday, she decides to work nonstop until she has answered 220 practice problems for her physics course. She starts work at 8:00 AM and uses a table...
-
RONA's cash position is significantly lower at the end of fiscal 2011 than the year before. Explain the reason for the decrease. Is this something you are concerned about? Explain. Why is RONA's cash...
-
The directors are preparing the published accounts of Dorman plc for the year to 31 October 2005. The following information is provided for certain of the items which are to be included in the final...
-
Key comparative figures ($ thousands) for Krispy Kreme and Tastykake follow: Required 1. Compute total asset turnover for the most recent two years for both Krispy Kreme and Tastykake using the data...
-
Consider the data set in Table 11.3.1, representing the ages (in years) and maintenance costs (in thousands of dollars per year) for five similar printing presses. a. Draw a scatterplot of this data...
-
During the summer, Tamir likes to swim at his local pool a few times a week. He is debating if he should buy a "season pass" that allows him to swim as many times as he wants or just pay each time he...
-
Salma wanted to sell her house and advertised it in the local newspaper on Monday for 400,000. Eshan saw the advertisement and rang Salma to make an appointment to see the house. During the He liked...
-
Give an example to show that two random variables can be uncorrelated but not independent. You must explicitly prove that they are uncorrelated but not independent (for the latter, you may invoke any...
-
please calculate the WACC for the (US-based) company 'XYZ", using the input factors as listed below. Please complete every single box in the solutions template by entering the correct value for each...
-
If you have $549 today and you think you can earn an interest rate of 6% per year, how many years until you have $865?
-
You are valuing a company today, using the FCF valuation method. The company's most current cash flow is 50 million, and you forecasted the free cash flows for the next 5 years in the table below....
-
An ice skater, depicted below, has a moment of inertia when her arms are stretched out ("a") of 1 = 2.0 kg-m. She rotates with an angular velocity of 1.0 revolutions/s in this configuration. When she...
-
McCormick & Company has decided in order for the company to have a minimal impact on current cash flows, the company will need to borrow seventy percent (70%) Loan to Value (LTV) of the $4,242,000.00...
-
Requirement 3. Prepare the balance sheet (with a proper heading) for 2018. (Enter all amounts in millions. Classify the balance sheet by selecting the proper title on all applicable subtotal lines....
-
Medi-Exam Health Services, Inc. (MEHS), located in a major metropolitan area, provides annual physical screening examinations, including a routine physical, EKG, and blood and urine tests. MEUS's...
-
Orthogonality: In Problems 1-3, find the real values of k for which the given vectors are orthogonal. If there are no such values show why? 1. 2. 3. 123 1k0 104 ]23 kok
-
In 1 840, Belgian demographer Pierre Verhulst modified the Malthus model by proposing that the rate of growth dy/dt of the world's population y(t) should be proportional to ky - cy2 ; thus dy/dt = ky...
-
For Problems, answer the following questions for each of the points A, B, C, and D: (a) Does the differential equation seem to have a unique solution through the point? (b) If yes, on what interval...
-
Construct a combined common-size and common-base year balance sheet for 2007. What will be the common-base year value for the 2007 net fixed assets? a. 0.89 b. 0.92 c. 1.12 d. 1.32 AHS INC. 2007...
-
What will be the value of AHS' equity multiplier during 2007? a. 0.44 b. 0.56 c. 1.78 d. 1.82 AHS INC. 2007 Income Statement (S in millions) Net sales S 9625 Cost of goods sold 5225 Depreciation 1890...
-
What will be the value of AHS' current ratio during 2007? a. 1.14 b. 1.42 c. 1.49 d. 1.53 AHS INC. 2007 Income Statement (S in millions) Net sales S 9625 Cost of goods sold 5225 Depreciation 1890...
Study smarter with the SolutionInn App