Skip to content

Commit 143a00e

Browse files
authored
Merge pull request #316 from lf-lang/decentralized-coord
Blog post on decentralized consistency
2 parents 05f8d69 + 2458dd0 commit 143a00e

16 files changed

+367
-57
lines changed

blog/2025-10-14-decentralized-consistency.md

Lines changed: 210 additions & 0 deletions
Large diffs are not rendered by default.

docs/assets/code/c/src/DecentralizedTimerAfter.lf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target C {
66
import Count, Print from "Federated.lf"
77

88
reactor PrintTimer extends Print {
9-
timer t(0, 1 sec)
9+
timer t(10 ms, 1 sec)
1010

1111
reaction(t) {=
1212
lf_print("Timer ticked at (%lld, %d).",
@@ -18,5 +18,5 @@ reactor PrintTimer extends Print {
1818
federated reactor {
1919
c = new Count()
2020
p = new PrintTimer()
21-
c.out -> p.in after 10 msec
21+
c.out -> p.in after 10 ms
2222
}

docs/assets/code/c/src/DecentralizedTimerAfterHandler.lf renamed to docs/assets/code/c/src/DecentralizedTimerHandler.lf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ reactor PrintTimer {
1313
lf_print("Received: %d at (%lld, %d)", in->value,
1414
lf_time_logical_elapsed(), lf_tag().microstep
1515
);
16-
=} STAA(0) {=
16+
=} tardy {=
1717
lf_print("****** Violation handler invoked at (%lld, %d). "
1818
"Intended tag was (%lld, %d).",
1919
lf_time_logical_elapsed(), lf_tag().microstep,
@@ -30,6 +30,7 @@ reactor PrintTimer {
3030

3131
federated reactor {
3232
c = new Count()
33+
@maxwait(10 ms)
3334
p = new PrintTimer()
34-
c.out -> p.in after 10 msec
35+
c.out -> p.in
3536
}

docs/assets/code/c/src/DecentralizedTimerSTA.lf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target C {
55

66
import Count, Print from "Federated.lf"
77

8-
reactor PrintTimer(STA: time = 10 ms) extends Print {
8+
reactor PrintTimer extends Print {
99
timer t(0, 1 sec)
1010

1111
reaction(t) {=
@@ -17,6 +17,7 @@ reactor PrintTimer(STA: time = 10 ms) extends Print {
1717

1818
federated reactor {
1919
c = new Count()
20+
@maxwait(10 ms)
2021
p = new PrintTimer()
2122
c.out -> p.in
2223
}

docs/assets/code/c/src/DecentralizedFeedbackSTAA.lf renamed to docs/assets/code/c/src/DecentralizedZeroDelayLoop.lf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target C {
2+
timeout: 3 s,
23
coordination: decentralized
34
}
45

@@ -16,14 +17,14 @@ reactor CountPrint {
1617
lf_print("***** CountPrint Received: %d at tag (%lld, %u)",
1718
in->value, lf_time_logical_elapsed(), lf_tag().microstep
1819
);
19-
=} STAA(forever) {=
20-
// This should never happen, but it is here to demonstrate the STAA violation handler.
21-
lf_print_warning("CountPrint: Safe to process violation!");
20+
=} tardy {=
21+
// This should never happen, but it is here to demonstrate the tardy violation handler.
22+
lf_print_warning("CountPrint: Message is tardy!");
2223
lf_print("Intended time: %lld", in->intended_tag.time - lf_time_start());
2324
=}
2425
}
2526

26-
reactor Double(STA: time = forever) {
27+
reactor Double {
2728
input in: int
2829
output out: int
2930

@@ -36,5 +37,6 @@ federated reactor {
3637
c = new CountPrint()
3738
p = new Double()
3839
c.out -> p.in
40+
@absent_after(forever)
3941
p.out -> c.in
4042
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
target C {
2+
timeout: 3 s,
3+
coordination: decentralized
4+
}
5+
6+
import CountPrint, Double from "DecentralizedZeroDelayLoop.lf"
7+
reactor CountPrintWithChecker extends CountPrint {
8+
9+
reaction(t, in) {=
10+
if (!in->is_present) {
11+
lf_print("***** CountPrint Failed to Receive response at tag (%lld, %u)",
12+
lf_time_logical_elapsed(), lf_tag().microstep
13+
);
14+
}
15+
=} tardy {=
16+
lf_print("***** CountPrint Received tardy input: %d at tag (%lld, %u)",
17+
in->value, lf_time_logical_elapsed(), lf_tag().microstep
18+
);
19+
=}
20+
}
21+
22+
federated reactor {
23+
c = new CountPrintWithChecker()
24+
p = new Double()
25+
c.out -> p.in
26+
@absent_after(20 ms)
27+
p.out -> c.in
28+
}

docs/assets/code/py/src/DecentralizedTimerAfter.lf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target Python {
66
import Count, Print from "Federated.lf"
77

88
reactor PrintTimer extends Print {
9-
timer t(0, 1 sec)
9+
timer t(10 ms, 1 sec)
1010

1111
reaction(t) {=
1212
print(
@@ -19,5 +19,5 @@ reactor PrintTimer extends Print {
1919
federated reactor {
2020
c = new Count()
2121
p = new PrintTimer()
22-
c.out -> p.inp after 10 msec
22+
c.out -> p.inp after 10 ms
2323
}

docs/assets/code/py/src/DecentralizedTimerAfterHandler.lf renamed to docs/assets/code/py/src/DecentralizedTimerHandler.lf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ reactor PrintTimer {
1414
f"Received: {inp.value} "
1515
f"at ({lf.time.logical_elapsed()}, {lf.tag().microstep})"
1616
)
17-
=} STAA(0) {=
17+
=} tardy {=
1818
print(
1919
"****** Violation handler invoked at "
2020
f"({lf.time.logical_elapsed()}, {lf.tag().microstep}). "
@@ -33,6 +33,7 @@ reactor PrintTimer {
3333

3434
federated reactor {
3535
c = new Count()
36+
@maxwait(10 ms)
3637
p = new PrintTimer()
37-
c.out -> p.inp after 10 msec
38+
c.out -> p.inp
3839
}

docs/assets/code/py/src/DecentralizedTimerSTA.lf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target Python {
55

66
import Count, Print from "Federated.lf"
77

8-
reactor PrintTimer(STA = 10 ms) extends Print {
8+
reactor PrintTimer extends Print {
99
timer t(0, 1 sec)
1010

1111
reaction(t) {=
@@ -18,6 +18,7 @@ reactor PrintTimer(STA = 10 ms) extends Print {
1818

1919
federated reactor {
2020
c = new Count()
21+
@maxwait(10 ms)
2122
p = new PrintTimer()
2223
c.out -> p.inp
2324
}

docs/assets/code/py/src/DecentralizedFeedbackSTAA.lf renamed to docs/assets/code/py/src/DecentralizedZeroDelayLoop.lf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target Python {
2+
timeout: 3 s,
23
coordination: decentralized
34
}
45

@@ -15,14 +16,14 @@ reactor CountPrint {
1516

1617
reaction(inp) {=
1718
print(f"***** CountPrint Received: {inp.value} at tag ({lf.time.logical_elapsed()}, {lf.tag().microstep})")
18-
=} STAA(forever) {=
19+
=} tardy {=
1920
# This should never happen, but it is here to demonstrate the STAA violation handler.
2021
print("CountPrint: Safe to process violation!")
2122
print(f"Intended time: {inp.intended_tag.time - lf.time.start()}")
2223
=}
2324
}
2425

25-
reactor Double(STA = forever) {
26+
reactor Double {
2627
input inp
2728
output out
2829

@@ -35,5 +36,6 @@ federated reactor {
3536
c = new CountPrint()
3637
p = new Double()
3738
c.out -> p.inp
39+
@absent_after(forever)
3840
p.out -> c.inp
3941
}

0 commit comments

Comments
 (0)