private void testListIsSorted(LockFreeList<Integer> list) throws Exception {
   ThreadID.reset();
   createAndRunThreads(list);
   for (AtomicMarkableReference<LockFreeList<Integer>.Node> node = list.head.next;
       node.getReference().key != Integer.MAX_VALUE;
       node = node.getReference().next) {
     assertTrue(node.getReference().key <= node.getReference().next.getReference().key);
   }
 }
  private void testInsertRemoveCountMatches(LockFreeList<Integer> list) throws Exception {
    ThreadID.reset();
    insertCount.set(0);
    removeCount.set(0);
    createAndRunThreads(list);
    int listSize = 0;
    AtomicMarkableReference<LockFreeList<Integer>.Node> pred = null;
    for (AtomicMarkableReference<LockFreeList<Integer>.Node> node = list.head.next;
        node.getReference().key != Integer.MAX_VALUE;
        node = node.getReference().next) {
      // System.out.print(node.getReference().key + "->");
      System.out.print(node.getReference().key + "->");
      listSize++;
    }

    assertEquals(listSize, insertCount.get() - removeCount.get());
  }
Exemple #3
0
 /**
  * 变更窗体匹配的图像组件大小
  *
  * @param w
  * @param h
  */
 public void resize() {
   this.id = ThreadID.get();
   if (handler != null) {
     int w = handler.getWidth(), h = handler.getHeight();
     if (w < 1 || h < 1) {
       w = h = 1;
     }
     if (w != tmp_width || h != tmp_height) {
       tmp_width = w;
       tmp_height = h;
     } else {
       Thread.yield();
       return;
     }
   }
   this.setBackground(GraphicsUtils.createIntdexedImage(tmp_width, tmp_height));
   this.flvVideo = new FLVEngine(tmp_width, tmp_height);
   this.sprites = new Sprites(tmp_width, tmp_height);
   this.desktop = new Desktop(baseInput, tmp_width, tmp_height);
 }
Exemple #4
0
  @Override
  public Void call() throws Exception {

    id = ThreadID.get();
    mBuffer.setId(id);
    tsStack.tsThreads[id] = this;

    Random rand = new Random();

    // Execute a push or pop on the stack. The frequency of push is controlled by percPush
    for (int i = 0; i < nOps; i++) {
      int x = rand.nextInt(100) + 1;
      if (x <= percPush) {
        ins(TsStackTest.idx.getAndIncrement());
      } else {
        tsStack.tryRem(System.nanoTime());
      }
    }
    return null;
  }