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

Value of input port in C target when not triggered, and after triggered. #1653

Closed
Jakio815 opened this issue Mar 15, 2023 · 5 comments
Closed
Labels
c Related to C target question Further information is requested

Comments

@Jakio815
Copy link
Collaborator

The example below is a simple lf code with triggering a single reaction with multiple timers which have different periods.
1.
Is there a default value for input ports in C target? In reactor Sum, at logical time 1 sec, in2 is not triggered because it's timer starts at logical time 2 sec. So, in2->is_present becomes 0, however in2->value is 0. This means it has a default value 0. Is this intended? I pasted the results below.

2.
Also, I see that the input port's value is valid even after the reaction is finished. For example on logical time 3 sec, the in2->value is still 2, even if it was not triggered. Is this intended? Or is it only happening on C target?

target C {
    timeout: 5 secs
}

reactor First {
    timer t1(1 sec, 1 sec)
    output out: int
    reaction(t1) -> out {= lf_set(out, 1); =}
}

reactor Second {
    timer t2(2 sec, 2 sec)
    output out: int
    reaction(t2) -> out {= lf_set(out, 2); =}
}

reactor Sum {
    input in1: int
    input in2: int

    reaction(in1, in2) {=
        lf_print("Logical time since start: \%lld nsec.",lf_time_logical_elapsed());
        if (in1->is_present){
            lf_print("in1->is_present: %d",in1->is_present);
        }
        lf_print("in2->is_present: %d",in2->is_present);
        lf_print("in2->value: %d\n",in2->value);
    =}
}

main reactor {
    f = new First()
    s = new Second()
    sum = new Sum()

    f.out, s.out -> sum.in1, sum.in2
}

image

image

@Jakio815 Jakio815 added the c Related to C target label Mar 15, 2023
@edwardalee
Copy link
Collaborator

In the C target, input ports are persistent. For an example of the kind of system for which this is particularly useful, see:

https://github.com/lf-lang/examples-lingua-franca/blob/main/C/src/rosace/README.md

The initial value of an input will be zero-ish, depending on the data type (the memory in which it is stored is allocated using calloc).

@cmnrd
Copy link
Collaborator

cmnrd commented Mar 15, 2023

Is this intended? Or is it only happening on C target?

As Edward mentioned, it is intended. However, it also currently only works this way in the C target.

@cmnrd cmnrd added the question Further information is requested label Mar 15, 2023
@Jakio815
Copy link
Collaborator Author

Thanks for the response. I'll check out the link.
But I'm still not sure. If it is intended, why does it only work in the C target?

@edwardalee
Copy link
Collaborator

Because we seem to have a disagreement about whether this is a good design choice. I think it is, and I think it should be supported in all targets.

@Jakio815
Copy link
Collaborator Author

Oh, I see. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c Related to C target question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants