mattunlv / ProcessJ-main-branch-old

ProcessJ Compiler Project
2 stars 4 forks source link

Timer unit of time off by a factor of 1000? #5

Closed cabelshrestha closed 7 years ago

cabelshrestha commented 7 years ago

can you try running this:

import std.io;
public proc void foo(long seed) [yield=true]{
  timer t;
  println("A:");
  println(t.read());
  t.timeout(1000);
  println("B:");
  println(t.read());
  println("Hello");
}
public proc void main(string args[]) [yield=true]{
  foo(0);
}

Do you see the output after the timeout? I don’t:

Air:ProcessJ matt$ pj test3
A:
1477678323350
Total execution time: 1.008585915

however, I think the timing is correct otherwise though I don’t understand why I don’t see the second set of output cause the generated code looks like:

switch(this.runLabel) {
  case 0: break;
  case 1: resume(1); break;
}

std.io.println( "A:" );
_ld2$temp = PJTimer.read();
std.io.println( _ld2$temp );
_ld1$t = new PJTimer(this, 1000);
try {
  _ld1$t.start();
  setNotReady();
  this.runLabel = 1;
  this._pd$seed = 0L;
  yield();
} catch (InterruptedException e) {
  System.out.println("PJTimer Interrupted Exception!");
}
label(1);
std.io.println( "B:" );
_ld3$temp = PJTimer.read();
std.io.println( _ld3$temp );
std.io.println( "Hello" );
terminate();

which seems ok?

matt

cabelshrestha commented 7 years ago

This wasn't an issue with timer unit of time. The program was deadlocking. This was one of the issues we were having with how scheduler checked for deadlocks. But now it has been fixed.

To detect deadlock, the scheduler checks the following:

if (inactivePool.getCount() == rq.size() && rq.size() > 0 && tq.isEmpty())

When the last timer is removed from the timer queue w/ a tq.take() and scheduler gets to the detection code before the timer queue sets the process ready to run, it terminates the program due to deadlock.

Modified the timerqueue class to indicate empty queue only after setting a process ready to run if it exists.