GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing raw.githubusercontent.com — raw.githubusercontent.com

import java.nio.*; import java.util.concurrent.locks.*; // Array stack is a bounded lock-based stack using an // array. It uses a common lock for both push and pop // operations. class ArrayStack { Lock lock; T[] data; int top; // lock: common lock for push, pop // data: array of values in stack // top: top of stack (0 if empty) @SuppressWarnings("unchecked") public ArrayStack(int capacity) { lock = new ReentrantLock(); data = (T[]) new Object[capacity]; top = 0; } // 1. Lock stack. // 2. Try push. // 3. Unlock stack. public void push(T x) throws BufferOverflowException { try { lock.lock(); // 1 tryPush(x); // 2 } finally { lock.unlock(); // 3 } } // 1. Lock stack. // 2. Try pop. // 3. Unlock stack. public T pop() throws BufferUnderflowException { try { lock.lock(); // 1 return tryPop(); // 2 } finally { lock.unlock(); // 3 } } // 1. Ensure stack is not full // 2. Save data at top. // 3. Increment top. protected void tryPush(T x) throws BufferOverflowException { if (top == data.length) // 1 throw new BufferOverflowException(); // 1 data[top++] = x; // 2, 3 } // 1. Ensure stack is not empty. // 2. Decrement top. // 3. Return data at top. protected T tryPop() throws BufferUnderflowException { if (top == 0) // 1 throw new BufferUnderflowException(); // 1 return data[--top]; // 2, 3 } }
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.