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 |
void main() { int k=ret(sizeof(float)); printf("\n here value is %d",++k); } int ret(int ret) { ret += 2.5; return(ret); }
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.
why the range of an unsigned integer is double almost than the signed integer.
write a c-program to find gcd using recursive functions
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }
#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }
given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }