read writers problem, C/C++ Programming

Assignment Help:
Readers Writers with Processes and Threads
Write two programs implementing ``reader pritority readers-writers synchronization'''' on files. One program will use processes, created with fork(), and synchronized with semaphores. The other program will use threads, created with pthread_create(), and synchronized with mutexes and conditions. In the following, the word "process" is used to describe either a process or thread, as appropriate.
Your program will create two readers and two writers. All four will access a common file, named ``SharedFile.'''' This file should contain a single number. The file should be created and given an initial value of 0 before the processes/threads are spawned.
The reader pseudocode:
repeat 20 times:
acquire read lock
read the number from SharedFile
release the read lock
print a message identifying the process, and the value read from SharedFile
sleep for a random period between 100 and 200 msec
The writer pseudocode:
repeat 20 times:
acquire write lock
read the number from SharedFile
increment it by a random value between 1 and 6
write the new value to SharedFile
release the write lock
print a message identifying the process, and the value written to SharedFile
sleep for a random period between 100 and 400 msec
Submit ONLY your C/C++ source code. Be sure to put your name and course in the comment header. The code must run on the "algebra and friends" machines. Use good programming style (comments, indentation, meaningful identifiers, etc.)

Related Discussions:- read writers problem

Program of conversion from basic to user-defined variable, Conversion from ...

Conversion from Basic to User-Defined variable Consider the following example. class Distance                  {                   public  :

Program to determine the number is prime or not, Write a function to determ...

Write a function to determine whether a number is prime: it will return true if the input is prime and false otherwise. Use it to see whether -7 is prime.

C program for select the char which u want , C Program for SELECT THE CHAR ...

C Program for SELECT THE CHAR WHICH U WANT #include stdio.h> #include conio.h> void main() {             void substr(char[], int *, int *);           int a,b

Boardcoloring, In this problem you are given a board in which some of the e...

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

Write a program for calculating value of an integer, Write a Program for Ca...

Write a Program for Calculating Value of an Integer? For a clear understanding of recursive function we shall see an illustration for calculating value of an integer. main() {

Decodethecode, 6999066263304447777077766622337778 -----> message sent by th...

6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space".

Theory, recursive sub programs

recursive sub programs

Loops, how to get plus asterisk pattern

how to get plus asterisk pattern

Want wellness software, Project Description: We are looking to have soft...

Project Description: We are looking to have software that we will use to track employee information regarding our wellness program. We would like the system to be able to follow

Menus, create a shopping cart in c++

create a shopping cart in c++

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd