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).
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 |
write a program in c to merge two array
Who could write how to find a prime number in dynamic array?
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print
Is the following code legal? struct a { int x; struct a *b; }
Write a Program that Inputs 10 Numbers in an Array and Show the Maximum Number
main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }
int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.