Do verify my solution. I have based my solution on the READERS-WRITERS problem (First).
semaphore pond ; // binary. mutual exclusion to the pond.
semaphore tiger; // for updating the tiger-count;
semaphore elephant; // for updating the elephant-count;
int tigercount = 0 ;
int elephantcount = 0 ;
tiger() {
P(tiger);
tigercount++ ;
if (tigercount == 1) { // if the first tiger comes to the pond, he will reserve the pond for tigers.
P (pond);
}
V(tiger);
// Drink Water
P(tiger);
tigercount-- ;
if (tigercount == 0) { // if it is the last tiger, then leave the pond for elephants.
V(pond);
}
V(tiger);
}
The elephant process will be similar.