Readers-Writers Problem Another classic synchronization problem Consists of a set of threads accessing some...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Readers-Writers Problem • Another classic synchronization problem • Consists of a set of threads accessing some shared data • Readers - threads that only reads the data o Writers threads that modifies the data • Typical example – Database access, linked list update and lookup • Synchronization requirements • Many readers can perform reading concurrently • Reading is prohibited while a writer is updating • Only one writer can perform updating at any time This is a solution (pseudocode) to the Readers-Writers problem given in the class. void Reader (void) { sem_t semMutex, readMutex; int readcount; void init (void) { } sem_init(&semMutex, 0, 1); sem init (&readMutex, 0, 1); readcount = 0; void Writer (void) { } sem_wait (&semMutex); do_writing ( ) ; sem_post(&semMutex); } sem_wait (&readMutex); readcount++; if (readcount == 1) sem_wait (&semMutex); sem_post (&readMutex); do_reading (); sem_wait (&readMutex); readcount--; if (readcount == 0) sem_post(&semMutex); sem_post(&readMutex); The above solution is implemented by using semaphores. Design another solution of the Readers- Writers problem by using condition variables and mutex locks. Write down your pseudo code to implement the writer () and Reader () functions. Please include declaration and initialization of necessary variables, if any. Readers-Writers Problem • Another classic synchronization problem • Consists of a set of threads accessing some shared data • Readers - threads that only reads the data o Writers threads that modifies the data • Typical example – Database access, linked list update and lookup • Synchronization requirements • Many readers can perform reading concurrently • Reading is prohibited while a writer is updating • Only one writer can perform updating at any time This is a solution (pseudocode) to the Readers-Writers problem given in the class. void Reader (void) { sem_t semMutex, readMutex; int readcount; void init (void) { } sem_init(&semMutex, 0, 1); sem init (&readMutex, 0, 1); readcount = 0; void Writer (void) { } sem_wait (&semMutex); do_writing ( ) ; sem_post(&semMutex); } sem_wait (&readMutex); readcount++; if (readcount == 1) sem_wait (&semMutex); sem_post (&readMutex); do_reading (); sem_wait (&readMutex); readcount--; if (readcount == 0) sem_post(&semMutex); sem_post(&readMutex); The above solution is implemented by using semaphores. Design another solution of the Readers- Writers problem by using condition variables and mutex locks. Write down your pseudo code to implement the writer () and Reader () functions. Please include declaration and initialization of necessary variables, if any.
Expert Answer:
Answer rating: 100% (QA)
The ReadersWriters Problem is a classic example of a situation that requires synchronization in multithreaded programming to avoid the simultaneous ac... View the full answer
Related Book For
Modern Systems Analysis And Design
ISBN: 9781292351629
9th Global Edition
Authors: Joe Valacich, Joey George
Posted Date:
Students also viewed these programming questions
-
Quatro Company issues bonds dated January 1, 2021, with a par value of $740,000. The bonds' annual contract rate is 13%, and interest is paid semiannually on June 30 and December 31. The bonds mature...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Version 1 Write a multi-threaded C++ program that gives readers priority over writers in accessing a shared variable. If any readers are waiting, they have priority over writer threads. Writers can...
-
The following is a sufficient condition, the Laplace-Liapounoff condition, for the central limit theorem: If X 1 , X 2 , X 3 , . . . is a sequence of independent random variables, each having an...
-
Kreiter Financial Services Ltd. recently purchased a portfolio of debt and equity securities. Financial vice-president Vicki Lemke and controller Ula Greenwood are in the process of classifying the...
-
A pipe can be used to measure the viscosity of a fluid. A liquid flows in a 1.7-cm smooth pipe 0.52 m long with an average velocity of 8 m/s. A head loss of 5 cm is measured. Estimate the kinematic...
-
Is there any notion of a trade-off between risk and return involved in an ecoefficiency portfolio matrix? How are green stars and dirty dogs related? In your answer cite examples from an industry...
-
Direct material variancessolving for price and usage variances. Fiberworks Company is a manufacturer of fiberglass toy boats. The company has recently implemented a standard cost system and has...
-
Write out a complete schedule (answers rounded to two decimal places) for the amortization of a $40, 000 loan with payments every 6 months at 16% interest compounded semiannually for 1 year. (Round...
-
Roberta Santos, age 41, is single and lives at 120 San-borne Avenue, Springfield, IL 60781. Her Social Security number is 123-45-6789. Roberta has been divorced from her former husband, Wayne, for...
-
As a healthcare manager, how are you going to convey the budgets to your supervisors or CFO?n Create an operating budget (minus staffing cost) and a capital budget for your area of responsibility....
-
Presented below is information related to Pina Company. Cost Retail Beginning inventory $225,045 $279,000 Purchases 1,380,000 2,108,000 Markups 96,100 Markup cancellations 13,800 Markdowns 35,000...
-
1) Using a graph and the concepts of consumer and producer surplus, explain why even though water is essential for human life, its market price is much lower than the price of many non-essential...
-
Jim and Kay Ross contributed to the support of their two children, Dale and Kim, and Jim's widowed parent, Grant. For 2022, Dale, a 19-year-old, full-time college student, earned $6,550 as a...
-
1. From the perspective of the marketer, when do wants become demands? 2. From the perspective of consumer behavior, when do needs become wants? 3) An audiophile who has invested $60,000 in a...
-
2021 2022 1. Units of work performed 80 2. Selling price $ 47,000 $ 45,200 Revenue effect of growth 3. Software implementation labour-hours 28,500 30,000 Cost effect of growth Haller Corporation is a...
-
IfP is a prime number and pa|O(G) then G has subgroup of order P OG has subgroup of order pa G has subgroup of order pa+1 none of these
-
Suppose the government bond described in problem 1 above is held for five years and then the savings institution acquiring the bond decides to sell it at a price of $940. Can you figure out the...
-
Match each of the key terms with the definition that best fits it. ____________ Technologies that enable the breaking of long-held business rules that inhibit organizations from making radical...
-
Match each of the key terms above with the definition that best fits it. Entity-relationship data model (E-R model) ____A detailed model that captures the overall structure of organizational data and...
-
Match each of the key terms above with the definition that best fits it. Political feasibility ____ Questions in interviews that ask those responding to choose from among a set of specified...
-
Describe the four procedures that can be used in conducting tests of controls.
-
Sampling is more likely to be used for certain types of tests of controls. What types are these?
-
For what types of procedures would sampling be appropriate?
Study smarter with the SolutionInn App