Question

please i need as soon as possible thank you A classical concurrent programming problem is called...

please i need as soon as possible thank you

A classical concurrent programming problem is called readers and writers. A data area is shared between several processes. Some processes, the writers, write to the area, the others, the readers, only read the data. At any given time only one reader can read the data or writer can write to the data. Also, no readers are allowed while a writer is executing.

Problem Statement: Devise suitable semaphores for this situation and design an outline of the reader and writer processes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

READER WRITER PROBLEM

In classical concurrent programming problem of reading and writing there are many processes in the system and a data area is shared among several processes.

The reader can only read the data and writer can write the data only one reader at a time can read the data or writer can write the data.If the two readers try accessing the same data areas or or two writer try to access the same data area then problems arises.the conditions are-

1) The writer should have exclusive control over critical section when writing so that no other reader or writer can perform any operation at the same time

2)The writer can access to the shared data area when no reader is waiting

3)Reader can access to the shared data area when no writer waiting

Two semaphore are used in this reading writing problems which are W and mutex and one variable read count is used

1) Semaphore W- This semaphore W is used by both reader and writer for entering in critical section and uses the wait and signal operations.

Critical section is data area where only one process can either perform read or write operation but only one process can gain entry into critical section at one time and one operation can be performed at one time.

2) Variable Readcount counts the number of processes reading in the critical section.

3) Mutex semaphore provides mutual exclusion when read count variable is updated means process first has to lock this mutex semaphore before changing readcount value.This semaphore is only used by reader.

There are two functions with semaphore

Wait() decrement semaphore value

Signal() increment semaphore value

semaphore can have either two value "0 or "1"

WRITER PROCESS

do

{

wait(W); //Writer request to enter critical section

//writing operation

Signal (W) //writer wants to leave critical section

} while(true);

1)Writer first request entry in critical section by wait(W) if W value less than 1 means value is 0 then can't perform write operationand if W value =1 then writer allowed to enter critical section and perform writing operation and if not allowed then it keep on waiting.

2) The writer after performing write operation gives signal(W) that write operation is done and other writer can either perform write or other reader can perform read operation.

INITIALIZATION

Mutex mutex;

Semaphore W=1;

Int readcount =1;

READER

do

{

wait(mutex) // reader want to enter critical section

Readcount ++;

If(readcount ==1)

{

Wait (W) ; // block write operation

}

Signal(mutex) // other reader can enter now in critical section

reading is performed

Wait(mutex) //reader want to leave critical section

Readcount --;

If(readcount==0)

{

Signal(W) // writer can now enters critical section

}

Signal(mutex)

}while(true); // reader leaves critical section.

1)The reader request entry in critical section by wait(mutex) is used in this statement this wait(mutex) is used for updating the value of read count that is reader uses mutual exclusion mutex for variables read count as read count variable can be updated by only one process at a time so after achieving the mutual exclusion by mutex it increment the read count variable readcount++ and make other reader to wait indicating  that read is to be performed.

2) If(read count =1)

This means reader is first reader so it makes the writer to wait by Wait(W) as in initialization value of W=1 but now the wait(W) decrement the value to 0 and 0 value means writer has to wait so that no other writer can write while first reader is reading  Means writer should wait so first reader blocks the writer.

3) Signal (Mutex) is used to signal  the other readers that one reader is now entering in critical section so other reader can now enter in critical section for their turn as signal(mutex) is giving signal to next readers so that next reader can update read count value.similarly all other reader will perform read operation.

4)Wait (mutex) indicates that now reader performed reading and want to leave the critical section so it lock again mutex for decrementing the read count value as wait(mutex) means it is telling other reader to wait so that other reader cannot change read count value while one reader is decrementing read count value.

5) After the reader perform reading then readcount will decrement as soon as all reader has performed reading then this readcount becomes 0 so it check for read count =0 if yes then it will give signal to writer to write  signal(W) so now writer can write.

6) Now signal(Mutex) means that reader has left the critical section and not need to control the variable read count so it is signalling the other process to continue and can change this read count variable.

Add a comment
Know the answer?
Add Answer to:
please i need as soon as possible thank you A classical concurrent programming problem is called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • pleasw answer as soon as possible . this is for my exam practice . please read...

    pleasw answer as soon as possible . this is for my exam practice . please read the code and answer the question In a system, there are multiple reader processes which read from a shared file and multiple writer processes which update a shared file. The following variables are shared among all processes: int readCounter; semaphore mutex, writeLock; Reader and writer processes are given in the following C++-like pseudo programs: Reader Process // Non-Critical Section P(mutex); Writer Process // Non-Critical...

  • Process Synchronization Assignment: Readers-Writers Problem . Consider readers and writers share a bounded array. ii. Writers...

    Process Synchronization Assignment: Readers-Writers Problem . Consider readers and writers share a bounded array. ii. Writers write an integer on the array. iii. Readers read and display contents of the array. iv. Writers will not be allowed to write if there is a reader reading the array. v. Only one writer can access the array at a time. But many readers can access the array at the same time. vi. All readers are blocked if there is a writer writing...

  • These multiple choice question, so you just need to write answer 1,2,3 or 4. But please...

    These multiple choice question, so you just need to write answer 1,2,3 or 4. But please read carefully the question before you answer. Thank you 17. Professional research ethics behaviors can help researchers implement which of the following research behaviors: A. honesty, B. subjectivity, C. correctness, D. efficiency, E. objectivity, or F. protection of participants? (1)A, C, D, E, and F (2)A, B, C, D, and E (3)A, B, C, D, and F (4)A, B, C, E, and F 18....

  • please answer as soon as possible. i only have 37 minutes left. i need help determining...

    please answer as soon as possible. i only have 37 minutes left. i need help determining whether or not the examples are word for word plagarism, paraphrasing plagarism, or not plagarism at all 14% Sun 12 29:06 AM Christoph Window Help Edi Safari Fle View History Bookmarks indiane edua In The Case Below The Original Source to How to Recognine PagiaemUndergraduate Cerication Tests: Se. Plagasm Ceficate Item 1 View In the case below, the original source material is given along...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Please use C programming to write the code to solve the following problem. Also, please use the i...

    Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

  • Please Use your keyboard (Don't use handwriting) Thank you.. PHC 231 I need new and unique...

    Please Use your keyboard (Don't use handwriting) Thank you.. PHC 231 I need new and unique answers, please. (Use your own words, don't copy and paste)*** Discuss Central Line-Associated Bloodstream Infection (CLABI) "or" Ventilator-Associated Pneumonia (VAP) outbreak in long-term acute care hospital settings. Address the following in your report: Characterize the epidemiology and microbiology Describe the agent and identify the host and the environment that is favorable for the infection. Discuss how the infections spread and the types of prevention...

  • please answer this after reading the article What is the actual problem? What are the known...

    please answer this after reading the article What is the actual problem? What are the known facts? What decision is to be made? How the problem ought to be solved? What are the alternatives? What are your recommendations? New AI tools make BI smarter — and more useful Data science democratized: What used to take data scientists months to prepare may soon be put together in a few days by data-astute business users. By Maria Korolov, Contributing Writer, CIO |...

  • I need help to write a nice introduction for experiment 6 please ( no hands write ) typing Thank you HEAT TREATMENT OF STEELS EXPERIMENT 6 EXPERIMENT 6 HEAT TREATMENT OF STEELS THEORY The Ef...

    I need help to write a nice introduction for experiment 6 please ( no hands write ) typing Thank you HEAT TREATMENT OF STEELS EXPERIMENT 6 EXPERIMENT 6 HEAT TREATMENT OF STEELS THEORY The Effect of Cooling Rate One of the most convenient methods for controlling the properties of a given steel, i.e., a steel whose composition is already fixed, consists of austenizing the steel and ten cooling to room temperature at some predetermined rate. A variation of cooling rates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT