+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
df69975
master
1class BoundedBufferMonitor { 2final int size =10 ; 3Object []buffer =new Object [size ]; 4int inBuf =0 ,outBuf =0 ,count =0 ; 5public synchronized void deposit (Object value ) { 6while (count ==size )// buffer full 7Util .myWait (this ); 8buffer [inBuf ] =value ; 9inBuf = (inBuf +1 ) %size ; 10count ++; 11if (count ==1 )// items available for fetch 12notify (); 13 } 14public synchronized Object fetch () { 15Object value ; 16while (count ==0 )// buffer empty 17Util .myWait (this ); 18value =buffer [outBuf ]; 19outBuf = (outBuf +1 ) %size ; 20count --; 21if (count ==size -1 )// empty slots available 22notify (); 23return value ; 24 } 25} 26