Question:
We would like to design and implement a programming solution
to the reader-writer problem
using semaphores in C language under UNIX.
We assume that we have three readers and two writers
processes that would run concurrently.
A writer is to update (write) into one memory location
(let’s say a variable of type integer named
temp initialized to 0). In the other hand, a reader is to
read the content of temp and display its
content on the screen in a formatted output. One writer can
access the shared data exclusively
without the presence of other writer or any reader, whereas,
a reader may access the shared
memory for reading with the presence of other readers (but
not writers).



Question: We would like to design and implement a programming solution to the reader-writer probl..

Answer / lina wahab

1- Displays a message that declares the id of the writer
and that it starts the updating
2- Sleeps a random number of seconds between 2 and 4
seconds [2, 4].
2- Increments the content of the shared data
3- Displays a message that declares the id of the writer
and that it finishes the updating
A reader process should read the content of the shared data
and displayed it on the
screen as following:
For each access to shared data for reading:
1- Sleeps a random number of seconds between 2 and 3
seconds [2, 3].
2- displays in one line: the content of the shared data as
well as the id of itself (the reading
process).
Important notes:
1. Let each process run up to 10 iterations.
2. Your solution should ensure the non starvation of readers

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Code Interview Questions

How to access command-line arguments?

4 Answers  


void main() { int k=ret(sizeof(float)); printf("\n here value is %d",++k); } int ret(int ret) { ret += 2.5; return(ret); }

1 Answers  


main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above

1 Answers   HCL,


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


main() { char a[4]="HELLO"; printf("%s",a); }

3 Answers   CSC,






x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);

2 Answers  


void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }

1 Answers  


Display the time of the system and display the right time of the other country

1 Answers  


find A^B using Recursive function

2 Answers  


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

1 Answers  


write a c-program to display the time using FOR loop

3 Answers   HCL,


Derive expression for converting RGB color parameters to HSV values

1 Answers  


Categories