User Tools

Site Tools


lab7

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lab7 [2018/03/11 23:18] francklab7 [2020/02/25 19:35] (current) franck
Line 1: Line 1:
-====== Lab ======+====== Lab ======
  
-In this lab, we consider a concurrent stack.  We start from the following skeleton of a sequential stack Note that the class Stack does not implement a stack correctly. +Test the listener gov.nasa.jpf.StackDepthChecker.  Use the JPF framework (TestJPF).  To receive feedback, submit your code **before** March 5 using the submit command:\\
-<code java> +
-/** +
- * A stack It stores integers. +
- * +
- * @author +
- */ +
-public class Stack { +
-  private int[] content; +
-  private int size; +
- +
-  /* +
-   * The maximal number of integers that can be stored in a stack. +
-   */ +
-  private final static int CAPACITY = 5; +
- +
-  /** +
-   * Initializes this stack to be empty. +
-   */ +
-  public Stack() { +
-    this.content = new int[Stack.CAPACITY]; +
-    this.size = 0; +
-  } +
- +
-  /** +
-   * Pushes the given integer onto this stack. +
-   * +
-   * @param value the integer to be pushed onto this stack. +
-   */ +
-  public void push(int value+
-    this.content[this.size] = value; +
-    this.size++; +
-    System.out.printf("Push %d\n", value); +
-  +
- +
-  /** +
-   * Pops the top of this stack and returns the integer. +
-   * +
-   * @return the top of this stack. +
-   */ +
-  public int pop() { +
-    this.size--; +
-    int value = this.content[this.size]; +
-    System.out.printf("Pop %d\n", value); +
-    return value; +
-  } +
-+
-</code> +
- +
-Implement the following classes. +
-  * The class Pusher.  Each Pusher object is a Thread that pushes the integers 0, 1, ..., 9 onto a stack.  The stack is provided as an argument to the constructor of the Pusher class.  The jar file [[:pop.jar|pop.jar]] contains the class Popper.  Each Popper object is a Thread that pops ten integers from a stack.  The stack is provided as an argument to the constructor of the Popper class. +
-  * The class Stack.  This class is based on the above skeleton and allows Threads to concurrently call the push and pop methods on the stack. +
-  * The class Main.  This class only contains a main method.  In the main method, a number of Popper and Pusher objects are created (for example, 10 Poppers and 5 Pushers) and all these Threads are run concurrently. +
- +
-To receive feedback, submit your code using the submit command:\\+
 <code> <code>
-submit 4315 lab7 <name of file>.java+submit 4315 lab4 <name of class>.java
 </code> </code>
  
lab7.1520810307.txt.gz · Last modified: 2018/03/11 23:18 by franck