read writers problem, C/C++ Programming

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.)
Posted Date: 1/21/2013 3:44:48 PM | Location : United States







Related Discussions:- read writers problem, Assignment Help, Ask Question on read writers problem, Get Answer, Expert's Help, read writers problem Discussions

Write discussion on read writers problem
Your posts are moderated
Related Questions

Is there any difficulty with the following : char*a=NULL; char& p = *a;? A: The result is indeterminate. You must never do this. A reference has to always refer to some object.

For the circuit shown in Figure, verify the p.d. across resistor R3. If the total resistance of the circuit is 100Ω, verify the current flowing by resistor R1. Find also the

char P[100]; double X=533.8*22500; sprintf(P,"%f %u",X,(unsigned int)X); MessageBox(P,"SSS"); //12010500.000 12010499

C Program for SWAPPING THE STRING #include conio.h> #include stdio.h> void main() {           char a[50],temp=0;           int i=0,c=0,c1=0,l=0;           clr

A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to execute an implied conversion of types. Its purpose is reserved ex

write a program to find the area under the curve y=f(x) between x=a & x=b


Readers Writers with Processes and Threads Write two programs implementing ``reader pritority readers-writers synchronization'''' on files. One program will use processes, created

Mathematical Statements and assignments    Within C we can directly load up the variable from within the program using the mathematical expression equates (=) e.g.   a= 'h'