Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdogs do not work with modal models #458

Closed
edwardalee opened this issue Jun 28, 2024 · 2 comments · Fixed by #459
Closed

Watchdogs do not work with modal models #458

edwardalee opened this issue Jun 28, 2024 · 2 comments · Fixed by #459
Assignees
Labels
bug Something isn't working

Comments

@edwardalee
Copy link
Contributor

The program below exhibits a race condition, where it sometimes (frequently) exits with the following output:

watchdog timeout.
watchdog reaction.
FATAL ERROR: _lf_advance_tag(): Attempted to move (elapsed) tag to (100000000, 1), which is earlier than or equal to the (elapsed) current tag, (100000000, 1).

The problem is apparently due to the fact that the expiration of the watchdog timeout is logically simultaneous with the next reaction, and that reaction triggers a mode change. Apparently, the runtime system advances one microstep, to (100000000, 1), and then, later, the watchdog schedules an event with that same tag.

target C {
  keepalive: true,
  timeout: 1 s
}

reactor Arbitrator(timeout: time = 100 ms) {
  input in1: double
  input in2: double

  watchdog watcher(timeout) {= lf_print("watchdog timeout."); =}

  initial mode Primary {
    reaction(in1) -> watcher {=
      lf_watchdog_start(watcher, 0);
    =}

    reaction(watcher) -> reset(Backup) {=
      lf_print("watchdog reaction.");
      lf_set_mode(Backup);
    =}
  }

  mode Backup {
    reaction(in2) -> watcher {=
      lf_watchdog_start(watcher, 0);
    =}
  }
}

main reactor {
  timer t(0, 100 ms)

  ar = new Arbitrator()

  reaction(t) -> ar.in1, ar.in2 {=
    lf_set(ar.in1, 0.0);
    lf_set(ar.in2, 0.0);
  =}
}
@edwardalee edwardalee added the bug Something isn't working label Jun 28, 2024
@edwardalee edwardalee self-assigned this Jun 28, 2024
@edwardalee
Copy link
Contributor Author

I believe this will be fixed by #459. The problem seems to be that in the Primary mode, the reaction to watcher was triggered at microstep 1, as it should be, but the modal models were setting the microstep to 1 after any mode transition. The fix is to increment the microstep rather than to set it to 1.

@edwardalee
Copy link
Contributor Author

Fixed via #459.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant