1
$\begingroup$

Can someone help me giving a pseudo code to this problem : There are two groups of processes , A and B. Maximum 3 Processes from group A or group B(only from one group) can use the given resource . How can this be implemented using semaphores ?

I'm thinking of something like this :

Semaphore work = 1
semaphore nProcesses = 3
Process A:

P(work);
P(nProcesses);

access(resource);

V(nProcesses);
….
V(work);

Process B:

P(work);
P(nProcesses);

access(resource);

V(nProcesses);
….
V(work);

..but I don't know when to free the work semaphore .

$\endgroup$
4
  • $\begingroup$ Use one semaphore to let only one group use it, and another semaphore to let only three processes use it? $\endgroup$
    – Draconis
    Jul 19, 2018 at 21:19
  • 1
    $\begingroup$ Which part are you having trouble with? $\endgroup$
    – Draconis
    Jul 19, 2018 at 21:20
  • $\begingroup$ Can you give a pseudo code for Process A and Process B ? I would initialize the first semaphore with 1 and the second with 3 ,but when should I free the first semaphore ? how can I know that there are no more from Process A so Process B can be able to start ? $\endgroup$
    – unnamed
    Jul 19, 2018 at 21:25
  • $\begingroup$ @Draconis I updated my question . $\endgroup$
    – unnamed
    Jul 19, 2018 at 21:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.