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
-
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...
-
Merchandise costing $2,300 is sold for $3,300 on terms 1/10, n/30. If the buyer pays within the discount period, what amount will be reported on the income statement as net sales and as gross profit?
-
Each of the following situations occurred during 2021 for one of your audit clients: 1. An inventory write-down due to obsolescence. 2. Discovery that depreciation expenses were omitted by accident...
-
What are the differentiating characteristics of chiefdoms and states?
-
You are the manager of a firm that charges customers $16 per unit for the first unit purchased, and $12 per unit for each additional unit purchased in excess of one unit. The accompanying graph...
-
Compute the future value of $1000 at an 8 percent interest rate15, 20, and 30 years into the future. What would the futurevalue be over these time horizons if the interest rate were 5percent?
-
A trader sold short a cotton futures contract @ 67.97 cents per pound. Contract size is 50,000 pounds. How much does the trader gain or lose in DOLLARS if he closed out his contract when futures...
-
The constant-pressure heat capacity of iron around its melting point of 1809 K is 46.02 J mol- K- for Fe(/) and 39.04 J mol- K- for Fe(s) in its face-centred cubic (fcc) allotrope. The standard...
-
A proposed cost-saving device has an installed cost of $695,000. The device will be used in a five-year project but is classified as three-year MACRS property for tax purposes. The required initial...
-
You have been offered a unique investment opportunity. If you invest $ 15000 today, you will receive $750 one year from? now, $2,250 two years from now, and $15,000 ten years from now. a. What is...
-
State the domain, vertical asymptote, and end behavior of the function. g(x) = ln (6x +12) + 1.8 Enter the domain in interval notation. To enter , type infinity. The vertical asymptote is x = As x...
-
Once upon a time, the treasurer of "Mighty Corporation" (MCO) decided to issue a bond (hereafter: The bond ) The bond would have a 8-year life and promised that the holder of the bond would receive:...
-
It was a hot summer day in May 2016 when Li An, the president of the Pakistani branch of the China Guangxi Corporation for International Techno-Economic Cooperation (GCITEC), received a startling...
-
Name some of the various types of financial intermediaries described in the chapter and indicate the primary reason(s) each was created.
-
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...
-
The duties of a nozzle and a diffuser are (a) Opposite to each other (b) Identical to each other (c) Not comparable at all (d) None of these.
-
Nozzles and diffusers are widely used in (a) Heat exchangers (b) Refrigeration systems (c) Rockets and other space vehicles (d) None of these.
-
Pick out the correct relation between the \(\mathrm{COP}\) of a refrigerator \(\left(\mathrm{COP}_{\mathrm{R}} ight)\) and that of the heat pump \(\left(\mathrm{COP}_{\mathrm{HP}} ight)\) (a)...
Study smarter with the SolutionInn App