sem bowl; sem chopsticks[n]; for(int i=0;i<n;i++) chopsticks[i].value=1; bowl.value=min(n-1,m)//bowl.value<=n-1,确保不死锁 while(True) { p(bowl); p(chopsticks[i]); p(chopsticks[(i+1]MOD n); 就餐; v(chopsticks[i]); v(chopsticks[(i+1]MOD n); v(bowl); }
2024-03-01 10:34:22
sem bowl; sem chopsticks[n]; for(int i=0;i<n;i++) chopsticks[i].value=1; bowl.value=min(n-1,m)//bowl.value<=n-1,确保不死锁 while(True) { p(bowl); p(chopsticks[i]); p(chopsticks[(i+1]MOD n); 就餐; v(chopsticks[i]); v(chopsticks[(i+1]MOD n); v(bowl); }