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...
-
Address each of the rhetorical questions posed at the end of the case. Add two challenges that Game Truck may face that are not mentioned in the case. Comment on how problematic each of the...
-
Determine the horizontal and vertical components of force at pin B and the normal force the pin at C exerts on the smooth slot. Also, determine the moment and horizontal and vertical reactions of...
-
The income statement and balance sheet for Clark Industries at March 31, 2010, are presented next: Requirements 1. Calculate the gross profit percentage for Clark Industries for the year. 2. The...
-
On January 1, 2006, Mason Co. entered into a 12-year lease on a building. The lease contract requires (1) annual (prepaid) rental payments of $ 36,000 each January 1 throughout the life of the lease...
-
Describe the circumstances leading up to the need to initiate a turnaround strategy for Etsy and how it was executed. Using the article titled Etsy: Crafting a turnaround to save the business and its...
-
The author purchased a slot machine (Bally Model 809) and tested it by playing it 1197 times. There are 10 different categories of outcomes, including no win, win jackpot, win with three bells, and...
-
Find distance between the parallel lines L1 X=-3-2t, y=5+3t, z=-2-t L2 X=-2+2s, y=-2-3s, z=3+s
-
Supply chain strategy which recognizes that all items are not the same, and that different item and market characteristics require different procurement and support strategies, as well as different...
-
The Veterans Administration allows practice in all states with a single state license although you still must follow the scope rules within the state that you are practicing in....If the VA can do...
-
M - Shock recently began production of a new product, a smartwatch with a capital investment amounting to RM 1 , 6 0 0 , 0 0 0 . For the first year, the company's target is to earn a net profit equal...
-
As consumers, we all interact with service companies every day, for example, the University, a taxi driver, a restaurant, a grocery store, etc. Describe and comment on service encounter (good or bad).
-
Stuart Daniels estimates that he will need $ 2 2 , 0 0 0 to set up a small business in 7 years. ( a ) How much ( in $ ) must Stuart invest now at 8 % interest compounded quarterly to achieve his goal?
-
According to Crepaz (2017), the US tends to differ from most European countries in terms of public policy; specifically, by having a smaller "welfare state," as measured by lower spending on social...
-
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...
-
Which of the following events most likely indicates the existence of related parties? a. Borrowing a large sum of money at a variable rate of interest. b. Making a loan without scheduled terms for...
-
Which of the following situations would most likely require special audit planning by the auditor? a. Some items of factory equipment do not bear identification numbers. b. Depreciation methods used...
-
An auditor obtains knowledge about a new client's business and its industry to a. Make constructive suggestions concerning improvements to the client's internal control. b. Develop an attitude of...
Study smarter with the SolutionInn App