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