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); }
原文地址:https://www.cnblogs.com/yangmenda/p/11708061.html
时间: 2024-10-22 15:25:17