正在加载图片...
5.4.2 Producer-Consumer with Monitors(1/4) program producerconsumer * monitor boundedbuffer; char buffer [N; / space for N items * int nextin, nextouti / buffer pointers intc。unt / number of items in buffer cond notfull, notempty: /*c。 ndition variab1esf。 r synchr。 nizatIon* void append (char x) whil if (count wait(notfull); / buffer is full; avoid overflow i buffer [nestin] =x; nextin =(nextin + 1) N; count++i / one more item in buffer * signal(notempty); / resume any waiting consumer * void take (char x) if (count wait(notempty); / buffer is empty; avoid underflow * x= buffer [nextout]i nextout =(nextout +1)8 N; count--; / one fewer item in buffer * signal(notfull); / resume any waiting producer /★ monitor body*/ nextin =o: nextout =o: count =o / buffer initially empty5.4.2 Producer-Consumer with Monitors(1/4) 20 whil e whil e
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有