Computer Science, asked by nikhilsaikamma, 8 months ago

You are asked to design and implement a new synchronization primitive that will allow multiple processes to block on an event until some other process signals the event. When a process signals the event, all processes that are blocked on the event are unblocked. If no processes are blocked on an event when it is signaled, then the signal has no effect. Implement the following using C functions. • intdoeventopen(); Creates a new event, returning event ID on success, -1 on failure. • intdoeventclose(inteventID); Destroy the event with the given event ID and signal any processes waiting on the event to leave the event. Return number of processes signaled on success and -1 on failure. • intdoeventwait(inteventID); Blocks process until the event is signaled. Return 1 on success and -1 on failure. • in doevents(in eventID); Unblocks all waiting processes; ignored if no processes are blocked. Return number of processes signaled on success and -1 on failure.

Answers

Answered by devagadamsetti03
1

Answer:

#include <iostream>  

#include <queue>  

struct Semaphore {  

   int value;  

   int q[100];

};

int P(Semaphore s)  

{  

   s.value = s.value - 1;  

   if (s.value < 0) {  

       s.q[0]=s.value;  

       

   }  

   else

       return 1;  

}  

 

int V(Semaphore s)  

{  

   s.value = s.value + 1;  

   if (s.value <= 0) {  

 

       // remove process p from queue  

       s.q[1]=s.value;  

   }  

   else

       return -1;  

}  

int main()

{

   int  p1=1,p2=2,p3=3,p4=4;

       if((p1+p2+p3+p4)%2==0)

       {

           printf("%d",1);

       }

       else

       {

           printf("%d",-1);

       }

}

Explanation:

Similar questions