コード例 #1
0
ファイル: Condition2.java プロジェクト: nabid337/CS162
  /** Test if this module is working. */
  public static void selfTest() {

    System.out.print("Enter Condition2.selfTest\n");

    Lock lock = new Lock();
    Condition2 condition = new Condition2(lock);

    KThread t[] = new KThread[10];
    for (int i = 0; i < 10; i++) {
      t[i] = new KThread(new Condition2Test(lock, condition));
      t[i].setName("Thread" + i).fork();
    }

    KThread.yield();

    lock.acquire();

    System.out.print("condition.wake();\n");
    condition.wake();

    System.out.print("condition.wakeAll();\n");
    condition.wakeAll();

    lock.release();

    System.out.print("Leave Condition2.selfTest\n");

    t[9].join();
  }
コード例 #2
0
ファイル: Communicator.java プロジェクト: eltonsky/nachos
  public static void selfTest() {
    comm = new Communicator();

    KThread t6 = new KThread(new TestListener()).setName("Listener 1");
    t6.fork();

    KThread t7 = new KThread(new TestListener()).setName("Listener 2");
    t7.fork();

    KThread t8 = new KThread(new TestListener()).setName("Listener 3");
    t8.fork();

    KThread t9 = new KThread(new TestListener()).setName("Listener 4");
    t9.fork();

    KThread t10 = new KThread(new TestListener()).setName("Listener 5");
    t10.fork();

    KThread t1 = new KThread(new TestSpeaker(123)).setName("Speaker 1");
    t1.fork();

    KThread t2 = new KThread(new TestSpeaker(456)).setName("Speaker 2");
    t2.fork();

    KThread t3 = new KThread(new TestSpeaker(789)).setName("Speaker 3");
    t3.fork();

    KThread t4 = new KThread(new TestSpeaker(101112)).setName("Speaker 4");
    t4.fork();

    KThread t5 = new KThread(new TestSpeaker(131415)).setName("Speaker 5");
    t5.fork();

    t1.join();
    t2.join();
    t3.join();
    t4.join();
    t5.join();
    t6.join();
    t7.join();
    t8.join();
    t9.join();
    t10.join();

    KThread.yield();
  }
コード例 #3
0
ファイル: KThread.java プロジェクト: kjyang/cs120f
 public void run() {
   for (int i = 0; i < 5; i++) {
     System.out.println("*** thread " + which + " looped " + i + " times");
     currentThread.yield();
   }
 }