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 .