Exemplo n.º 1
0
    public void run() {
      Lib.debug('t', "### Try to listen from " + KThread.currentThread().toString());

      int res = comm.listen();

      Lib.debug('t', "### listened " + res + " from " + KThread.currentThread().toString());
    }
Exemplo n.º 2
0
    /**
     * The exception handler. This handler is called by the processor whenever
     * a user instruction causes a processor exception.
     *
     * <p>
     * When the exception handler is invoked, interrupts are enabled, and the
     * processor's cause register contains an integer identifying the cause of
     * the exception (see the <tt>exceptionZZZ</tt> constants in the
     * <tt>Processor</tt> class). If the exception involves a bad virtual
     * address (e.g. page fault, TLB miss, read-only, bus error, or address
     * error), the processor's BadVAddr register identifies the virtual address
     * that caused the exception.
     */
    public void exceptionHandler() {
	Lib.assert(KThread.currentThread() instanceof UThread);

	UserProcess process = ((UThread) KThread.currentThread()).process;
	int cause = Machine.processor().readRegister(Processor.regCause);
	process.handleException(cause);
    }
Exemplo n.º 3
0
    public void run() {
      lock.acquire();

      System.out.print(KThread.currentThread().getName() + " acquired lock\n");
      condition.sleep();
      System.out.print(KThread.currentThread().getName() + " acquired lock again\n");

      lock.release();
      System.out.print(KThread.currentThread().getName() + " released lock \n");
    }
Exemplo n.º 4
0
  /**
   * Put the current thread to sleep for at least <i>x</i> ticks, waking it up in the timer
   * interrupt handler. The thread must be woken up (placed in the scheduler ready set) during the
   * first timer interrupt where
   *
   * <p>
   *
   * <blockquote>
   *
   * (current time) >= (WaitUntil called time)+(x)
   *
   * </blockquote>
   *
   * @param x the minimum number of clock ticks to wait.
   * @see nachos.machine.Timer#getTime()
   */
  public void waitUntil(long x) {
    // disable interrupts
    Machine.interrupt().disable(); // let's see if this works? DAC DEBUG
    // calculate wakeTime
    long wakeTime = Machine.timer().getTime() + x;
    // create AlarmBucket
    AlarmBucket Abuck = new AlarmBucket(wakeTime, KThread.currentThread());
    // add current thread (alarm bucket) to waitQueue
    waitQueue.add(Abuck);
    // put current thread to sleep
    KThread.currentThread().sleep();

    return;
  }
Exemplo n.º 5
0
    /**
     * Start running user programs, by creating a process and running a shell
     * program in it. The name of the shell program it must run is returned by
     * <tt>Machine.getShellProgramName()</tt>.
     *
     * @see	nachos.machine.Machine#getShellProgramName
     */
    public void run() {
	super.run();

	UserProcess process = UserProcess.newUserProcess();
	
	String shellProgram = Machine.getShellProgramName();	
	Lib.assert(process.execute(shellProgram, new String[] { }));

	KThread.currentThread().finish();
    }
Exemplo n.º 6
0
  /**
   * Atomically release the associated lock and go to sleep on this condition variable until another
   * thread wakes it using <tt>wake()</tt>. The current thread must hold the associated lock. The
   * thread will automatically reacquire the lock before <tt>sleep()</tt> returns.
   */
  public void sleep() {
    Lib.assertTrue(conditionLock.isHeldByCurrentThread());

    boolean intStatus = Machine.interrupt().disable();

    conditionLock.release();
    waitQueue.waitForAccess(KThread.currentThread());
    KThread.sleep();
    conditionLock.acquire();

    Machine.interrupt().restore(intStatus);
  }
Exemplo n.º 7
0
 /**
  * The timer interrupt handler. This is called by the machine's timer periodically (approximately
  * every 500 clock ticks). Causes the current thread to yield, forcing a context switch if there
  * is another thread that should be run.
  */
 public void timerInterrupt() {
   // disable interrupts (maybe not necessary)
   Machine.interrupt().disable(); // let's see if this works?
   // get current time
   long currentTime = Machine.timer().getTime();
   // go through waitQueue and put each thread that is "less than" current wait time on ready queue
   AlarmBucket placeholder = null;
   int count = waitQueue.size();
   while (count > 0) {
     placeholder = waitQueue.peek();
     if (placeholder.getTime() <= currentTime) {
       placeholder = waitQueue.poll();
       placeholder.getKThread().ready();
       count = waitQueue.size();
     } else {
       count = 0;
     }
   }
   // yield current thread
   KThread.currentThread().yield();
   // Machine.interrupt().enable(); //let's see if this works? DAC DEBUG
 }
Exemplo n.º 8
0
    public void run() {
      Lib.debug('t', "### Speak " + word + " from " + KThread.currentThread().toString());

      comm.speak(word);
    }
Exemplo n.º 9
0
    /**
     * Returns the current process.
     *
     * @return	the current process, or <tt>null</tt> if no process is current.
     */
    public static UserProcess currentProcess() {
	if (!(KThread.currentThread() instanceof UThread))
	    return null;
	
	return ((UThread) KThread.currentThread()).process;
    }