lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
220 stars 57 forks source link

Actions remain "present" after they're scheduled for the first time (C-Target) #2291

Open AneesHl opened 1 month ago

AneesHl commented 1 month ago

In the C-Target, once an action is scheduled for the first time then action_id->is_present always returns true. As an example, the following program

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

main reactor {
  state ms_250 : time = 250 msec
  logical action _logical
  physical action _physical : float
  timer t(0 msec, 250 msec);

  reaction(startup) -> _logical, _physical {=
    printf("\n--- Startup Reaction ---\n");

    lf_schedule(_logical, self->ms_250);
    lf_schedule(_physical, self->ms_250 * 2);
  =}

  reaction(_logical, _physical, t) {=
    printf("\n--- Reaction 2 ---\n");

    if (_logical->is_present) {
      printf("_logical->is_present = true\n");
    }
    if (_physical->is_present) {
      printf("_physical->is_present = true\n");
    }

    printf("~> elapsed logical time  = " PRINTF_TIME "\n", lf_time_logical_elapsed());
  =}
}

it produces the following result:

...
--- Startup Reaction ---

--- Reaction 2 ---
~> elapsed logical time  = 0

--- Reaction 2 ---
_logical->is_present = true
~> elapsed logical time  = 250000000

--- Reaction 2 ---
_logical->is_present = true
~> elapsed logical time  = 500000000

--- Reaction 2 ---
_logical->is_present = true
_physical->is_present = true
~> elapsed logical time  = 500410000

--- Reaction 2 ---
_logical->is_present = true
_physical->is_present = true
~> elapsed logical time  = 750000000

--- Reaction 2 ---
_logical->is_present = true
_physical->is_present = true
~> elapsed logical time  = 1000000000
...