I'll write pseudo-code for OS topics. (Cai cry
void move(){
do{
think();
int i;
for(i=0;i<5;++i){
bool temp=wait(chopsticks[i],chopsticks[(i+1)%5]);
if(temp==true){
eat(i);
release(chopsticks[i],chopsticks[(i+1)%5]);
}
}
}while(1);
}
Here is mainly the and semaphore mechanism
The core iswait(chopsticks[i],chopsticks[(i+1)%5])