Process problem (C++ implementation of philosopher's meal)

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])

Guess you like

Origin blog.csdn.net/qq_43477024/article/details/109680088