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...
-
Use the means-objectives network in Figure 6.8 to create a list of alternatives for improving automotive safety. Try to create at least one alternative for each objective listed. Maximize Safety...
-
The following data (in pounds), which were selected randomly from a normally distributed population of values, represent measurements of a machine part that is supposed to weigh, on average, 8.3...
-
Choose a country from three of the regions presented in Table 6.7. Using the Internet, collect as much information as you believe is needed to identify the potential for market segments based on age,...
-
A beginning accounting student tried to complete a work sheet for Joyce Lee's Tax Service. The following adjusting entries were to have been analyzed and entered onto the work sheet. The work sheet...
-
5. WORK HEALTH & SAFETY Provide at least three types of hazards, corresponding risks, rating and control measures. Risk Rating (Low/Medium/High) Control measures (Current/Required)
-
B 9 50 01 02 03 04 05 06 107 108 109 110 111 112 113 114 115 116 117 40. Based on the information on the "Bank Reconciliation" sheet prepare the journal entry required to increases cash. 41. Based on...
-
If our regression equation is y= XB + u, where we have T observations and k regressors, what will be the dimension of Busing the standard matrix notation O TXk O TX1 O kX1 O kXk
-
What does the abbreviation CPC stand for? what is its working ?write a brief discussion .
-
What are the problems with the ideal CNN model? explain all the problems .
-
Write a function append_fr : 'a list -> 'a list -> 'a list that returns a list containing the elements in the first list at the front of the second, with the order of the two lists preserved. Your...
-
A 3 0 0 g bird flying along at 6 . 0 0 m / s sees a 1 5 . 0 g insect heading straight toward it with a speed of 2 5 . 0 m / s ( as measured by an observer on the ground, not by the bird ) . The bird...
-
A horizontal torque=10.0 Nm is applied at the edge of the top face of a hollow cylindrical rod. The base of the rod is fixed to the surface. The outer radius of the cylinder is ro=0.040 m and the...
-
Project L requires an initial outlay at t = 0 of $49,878, its expected cash inflows are $10,000 per year for 8 years, and its WACC is 10%. What is the project's IRR?
-
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...
-
The basketball player from Example 2 is asked to shoot three free throws 100 times. Compute the mean number of free throws made. Approach The player shoots three free throws and the number made is...
-
A term life insurance policy will pay a beneficiary a certain sum of money upon the death of the policyholder. These policies have premiums that must be paid annually. Suppose an 18- year-old male...
-
Find the standard deviation of the discrete random variable given in Table 1 from Example 2. Approach We will use Formula (2a) with the unrounded mean X = 2.39. Approach We will use Formula (2b)...
Study smarter with the SolutionInn App