Skip to content

Commit

Permalink
Merge pull request #1370 from lf-lang/1368-memory-error-with-reaction…
Browse files Browse the repository at this point in the history
…s-writing-to-multiple-ports

Adjustment of code generator to address #1368
  • Loading branch information
lhstrh authored Sep 17, 2022
2 parents a47cbd3 + 15e1df3 commit d39729c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ private static String deferredFillTriggerTable(
}
var cumulativePortWidth = 0;
for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) {
// If this port does not have any destinations, do not generate code for it.
if (port.eventualDestinations().isEmpty()) continue;

code.pr("for (int i = 0; i < "+reaction.getParent().getTotalWidth()+"; i++) triggers_index[i] = "+cumulativePortWidth+";");
for (SendRange srcRange : port.eventualDestinations()) {
if (currentFederate.contains(port.getParent())) {
Expand Down
35 changes: 35 additions & 0 deletions test/C/src/MultipleOutputs.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This test checks for one of the issues arised in the solution of EECS149 Lab
// Chapter 7. In this case, a reactor has two output ports, the first one of
// which is dangling. The generated code should not have any segmentation
// faults.
target C {
timeout: 1 sec,
fast: true
}

reactor C {
output x: int
output z: int
timer t(0, 100 msec)

reaction(t) -> x, z {=
lf_set(x, 42);
lf_set(z, 44);
=}
}

main reactor {
c = new C()
state triggered: bool(true)

reaction(c.z) {=
lf_print("c.z = %d", c.z->value);
self->triggered = true;
=}

reaction(shutdown) {=
if (!self->triggered) {
lf_print_error_and_exit("Reaction never triggered.\n");
}
=}
}

0 comments on commit d39729c

Please # to comment.