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

#title. c program on pebble merchant, #questThere is a pebble merchant. He ...

#questThere is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doin

C program for bank account, Aim: To implement a program for bank account u...

Aim: To implement a program for bank account using static data type. Code: class bank {             static int acc_no;             int acc;             float b

C program to demonstrate call by reference, C program to demonstrate call b...

C program to demonstrate call by reference: void disp(int *,int*,int*,int*); void main() {                 int a=2,b=3, sum,mul;                 printf("Enter 1st n

Define bitwise-shift operators, Define Bitwise-Shift Operators? The shi...

Define Bitwise-Shift Operators? The shift operators perform suitable shift by operator on the right to the operator on the left. The right operator should be positive. The va

What does odbc do in context with php, What does ODBC do in context with PH...

What does ODBC do in context with PHP? PHP supports many databases such as dBase, Microsoft SQL Server, Oracle, etc. however, it also supports databases such as filePro, FrontB

Program is to find the area of room, Program is to find the area of room: ...

Program is to find the area of room: Program is to find the area of room with default values using classes & object class room   {   private:     int len;     i

Singly linked list, For this program you will add and test 2 new member fun...

For this program you will add and test 2 new member functions to the IntSLList class posted on the website. The two member functions are: insertByPosn(int el, int pos) Assuming t

Sums a sequence of integers, assume that the first integer read with cin sp...

assume that the first integer read with cin specifies the number of values remaining to be entered. that program should read only one value each time cin is executed .a typical inp

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