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

Centralized coordination fails with usage of broadcast connections #2473

Open
erlingrj opened this issue Feb 13, 2025 · 0 comments
Open

Centralized coordination fails with usage of broadcast connections #2473

erlingrj opened this issue Feb 13, 2025 · 0 comments
Labels
bug Something isn't working c Related to C target compiler federated

Comments

@erlingrj
Copy link
Collaborator

erlingrj commented Feb 13, 2025

I am getting STP violations on centrally coordinated programs that are using broadcast connections. This might be solved by #2459

To reproduce run this program:

Image

target C;

reactor Wrapper {
  output [2] out: int
  input [2] in: int

  r = new R()

  // This connection statement causes STP violations
  (r.out)+ -> out

  reaction(in) -> r.in {=
    lf_set(r.in, 0);
  =}

}

reactor R {
  output out: int
  input in: int
  preamble {=
    // Schedule an event roughly every 200 msec.
    void* external(void* a) {
      int i = 0;
      while (true) {
        lf_sleep(MSEC(500));
        lf_schedule_int(a, 0, i++);
      }
    }
  =}

  state thread_id: lf_thread_t = 0
  physical action a: int
  timer t (0, 10 msec)

  reaction(startup) -> a {=
    // Start a thread to schedule physical actions.
    lf_thread_create(&self->thread_id, &external, a);
  =}

  reaction(a) -> out {=
    interval_t elapsed_time = lf_time_logical_elapsed();
    printf("Action triggered with %d at logical time %lld nsec after start.\n", a->value, elapsed_time);
    lf_set(out, a->value);
  =}

  reaction(t) {= =}


  reaction(in) {=
    printf("Received input at logical time %lld nsec after start.\n", lf_time_logical_elapsed());
  =}
}


federated reactor {
  r = new [2] Wrapper()

  r.out -> interleaved(r.in)
}

The problem goes away by replacing the broadcast connection with a reaction:
Image

target C;

reactor Wrapper {
  output [2] out: int
  input [2] in: int

  r = new R()

// Replacing broadcast connection with a reaction and it works
  reaction(r.out) -> out {=
    lf_set(out[0], r.out->value);
    lf_set(out[1], r.out->value);
  =}

  reaction(in) -> r.in {=
    lf_set(r.in, 0);
  =}

}

reactor R {
  output out: int
  input in: int
  preamble {=
    // Schedule an event roughly every 200 msec.
    void* external(void* a) {
      int i = 0;
      while (true) {
        lf_sleep(MSEC(500));
        lf_schedule_int(a, 0, i++);
      }
    }
  =}

  state thread_id: lf_thread_t = 0
  physical action a: int
  timer t (0, 10 msec)

  reaction(startup) -> a {=
    // Start a thread to schedule physical actions.
    lf_thread_create(&self->thread_id, &external, a);
  =}

  reaction(a) -> out {=
    interval_t elapsed_time = lf_time_logical_elapsed();
    printf("Action triggered with %d at logical time %lld nsec after start.\n", a->value, elapsed_time);
    lf_set(out, a->value);
  =}

  reaction(t) {= =}


  reaction(in) {=
    printf("Received input at logical time %lld nsec after start.\n", lf_time_logical_elapsed());
  =}
}


federated reactor {
  r = new [2] Wrapper()

  r.out -> interleaved(r.in)
}
@erlingrj erlingrj added bug Something isn't working compiler c Related to C target federated labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c Related to C target compiler federated
Projects
None yet
Development

No branches or pull requests

1 participant