7 processes are characterized by 4 readers and 3 writers Up

7 processes are characterized by 4 readers and 3 writers.

Up to 3 reader processes can be inside their critical section without any writer process. For writer process to go into its critical section, it should check whether there is any reader or writer process in the critical section.

Critical section in this problem is reading shared data buffer for reader and updating shared data buffer for writer processes. It is up to you to implement any shared data for readers and writers but you have to specify clearly following things in your sample output.

- When reader or writer enters its critical section, it has to report whether there are any reader(s) or writer(s) other than itself.

- You may print out the data you read or write when you implement real buffer.(Optional)

- You have to print out \"Panic Messages\" when the rules behind this semi critical section problem are not observed.

In your main program, you run the random number generator function to choose proces to execute. The chosen process starts (resumes) execution and after one instruction, it will be returned. (You should force each process to run exactly one instruction then return an wait for its turn).

You can implement this using switch statement in C++. Each process is one big switch statement and will be returned after each instruction. You need to keep track of program counter of each process to resume at the right place once it will be chosen to run by keeping global counter variable per process.

You should implement binary and counting semaphores.

You should use swap operation.

Solution

#include<iostream>

#include<semaphore>

typedef struct {

int value;

struct process *L;

} semaphore;

void main()

{

boolean c[n]=false;

int num[n]=0;

cout<<\"Number of process: \";

cin>>n;

do {

c[i] = false;

for(j=0; j<n; j++) {

while( c[j]);

while( (num[j]!=0) && (num[j, j] < num[I,i]));

}

critical section

num[i]=0;

remainder section

} while(1);

for(i=1;i<=n;i++)

switch(boolean p[i])

case TRUE:

{

c++;

signal(p);

}

case FALSE:

wait(p);

break;

}

wait(s):

s.value--;

if(s.value<0)

{

s.l=s.l+1;

block;

}

signal(s):

s.value++;

if(s.value<=0)

{

s.l=s.l-1;

signal(s);

}

boolean l=false;

do{

k=true;

while(k==true)

swap(l,k);

critical section

l=false

remainder section

}

void swap(boolean &a, boolean &a)

{

boolean temp = a;

a=b;

b=temp;

}

}

7 processes are characterized by 4 readers and 3 writers. Up to 3 reader processes can be inside their critical section without any writer process. For writer p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site