COP4600_2-6 - COP4600*Exam#1 next wednesday An OO approach to a P C class MyBoundedBuffer a first attempt class BrokenBoundedBuffer implements

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP4600 2-6-10 *Exam #1 next wednesday class MyBoundedBuffer: a first attempt class BrokenBoundedBuffer<E> implements BoundedBuffer { private E[] buffer; private int count; // number items in buffer private int in = 0; // where next item will be inserted private int out = 0; // where next item will be taken from public BrokenBoundedBuffer( int size ) { buffer = new E[ size ]; // Java will not allow this } public void insert( E item ) { while ( count == buffer.length ) ; //sit and spin until space avail: evil busy wait ++count; buffer [ in ] = item; in = ( in + 1 ) % buffer.length; } public E remove() { while ( count == 0 ) ; //sit and spin until an item becomes available --count; E item = buffer[ out ]; out = (out + 1) % buffer.length; return item; } } Scenario and the correct behavior of a BB in that context Assume: 1 P(roducer) and 1 C(onsumer) Assume: a P makes tuff 5X faster than a C can use it. P_ideal will show the behavior of a P with an unbounded buffer buffer will show the actual contents of a buffer of size 3 P_buff3 will show the behavior of a P with a |buffer| == 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P_ideal Buffer3 P_buff3 C make() ___ make() remove() insert() X__ insert() make() X__ make() ___ consume()
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course ECON 2023 taught by Professor Rush during the Spring '08 term at University of Florida.

Page1 / 5

COP4600_2-6 - COP4600*Exam#1 next wednesday An OO approach to a P C class MyBoundedBuffer a first attempt class BrokenBoundedBuffer implements

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online