Open cmnrd opened 3 years ago
This is a good point. I think we could probably get rid of keepalive.
We've had this discussion before. See: https://github.com/lf-lang/lingua-franca/issues/131#issuecomment-611813536
That earlier discussion was closed with the conclusion that keepalive
could not be automatic, but I don't quite understand the reasoning there either because we could distinguish between generated physical actions and programmed ones.
These were my 2 cents in that thread:
If the event queue is empty, and there are only logical actions, no new events can emerge -- unless we're scheduling logical events asynchronously (which would be an abuse of logical actions). In other words, there would be no point in enforcing
keepalive
in that scenario. I think we should eliminate thekeepalive
target property altogether (not just for the C target) and implement the behavior as you suggest; enforce keep alive if there are physical actions.
Actually, re-reading my comment from back then (about physical connections), I think it is reasonable to force keepalive to be true when using physical connections. The programmer still has the option of specifying a timeout or invoking stop_request. So I agree that we should eliminate the keepalive target property.
Given the recent development in #546, I wonder if we still need the keepalive target property. If there are no physical actions in the program, then
keepalive=true
does not make any sense because there is no way for new events to be created once the event queue is empty. If there are physical actions, then we automatically setkeepalive=true
to account for asynchronous events. We could also setkeepalive=false
explicitly in case we still want the program to terminate when there are no more events. However, I am wondering: is this a common use-case?Couldn't we simply omit the keepalive property if we set it automatically to the expected value? In the presence of physical actions,
keepalive=false
is likely a bad idea in most cases, because it is unpredictable. Depending on the precise timing of physical events, the program could nondeterminsitcally terminate at different points each time we run it. I think a controlled shutdown using an API call likerequest_stop()
when the program reaches a certain state is generally the preferred option for stopping programs with physical actions.