13.07.2015 Views

5. Predavanje - VTS NS

5. Predavanje - VTS NS

5. Predavanje - VTS NS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Upotreba semaforaBoundedBuffer::BoundedBuffer () :mutex(1), spaceAvailable(N), itemAvailable(0),head(0), tail(0) {}void BoundedBuffer::append (Data* d) {spaceAvailable.wait();mutex.wait();buffer[tail] = d;tail = (tail+1)%N;mutex.signal();itemAvailable.signal();}Data* BoundedBuffer::take () {itemAvailable.wait();mutex.wait();Data* d = buffer[head];head = (head+1)%N;mutex.signal();spaceAvailable.signal();return d;}76/285

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!