void Monge(){ m->P(); if((monge> 0 && canibal>0)|| monge>1){ printf("LLego un monge \nSe va el barco con monge\n"); monge--; if(canibal== 0){ monge--; mon->V(); mon->V(); } else{ canibal--; mon->V(); cani->V(); } m->V(); }else{ printf( "Llega un monge \n"); monge++; m->V(); mon->P(); } } void Canibal(){ m->P(); if((monge> 1 && canibal==0) || canibal>1){ printf("LLego un canibal \nSe va el barco con canibal\n"); canibal--; if(monge<2){ canibal--; cani->V(); cani->V(); } else{ monge--; mon->V(); cani->V(); } m->V(); }else{ printf( "Llega un canibal \n"); canibal++; m->V(); cani->P(); } } int main(){ int monge=0;int canibal=0; Semaphore*mon=new Semaphore("Semaforo AguaH",0); //H Semaphore*cani=new Semaphore("Semaforo AguaO",0); //O Semaphore*m=new Semaphore("Mutex",1); for(int i=0;i<20;i++){ if(rand()%2==0){ Fork(Monge); } else{ Fork(Canibal); } } }