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

main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above

5 Answers   HCL,


What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++<n) p = &arr[i]; *p = 0; }

1 Answers  


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

3 Answers   HCL,


main() { int i=10; i=!i>14; Printf ("i=%d",i); }

1 Answers  


how to check whether a linked list is circular.

11 Answers   Microsoft,






Write a single line c expression to delete a,b,c from aabbcc

2 Answers   Microsoft,


Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.

5 Answers   Amazon, Microsoft,


#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

1 Answers  


Given n nodes. Find the number of different structural binary trees that can be formed using the nodes.

16 Answers   Aricent, Cisco, Directi, Qualcomm,


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,


what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }

10 Answers  


What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }

1 Answers  


Categories