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

Preempt keyword for reactions #280

Closed
Soroosh129 opened this issue Feb 12, 2021 · 3 comments
Closed

Preempt keyword for reactions #280

Soroosh129 opened this issue Feb 12, 2021 · 3 comments
Labels
enhancement Enhancement of existing feature exclude Exclude from change log

Comments

@Soroosh129
Copy link
Contributor

It might be interesting for soft-real time applications to implement a feature that can limit the physical time that a reaction is allowed to execute:

reaction(foo) {=
=} preempt (10 msec) {=
   // Preempt the reaction after 10 msec has passed in physical time
=}

This can be currently done in the target language (at least in C) in many ways. One way to do it is the following:

reactor Foo {
    input in:int;
    preamble {=
        int a = 0;
        void *gpu_thread(void* nonsense) {
            // CUDA
            // Tensorflow
            sleep(alongtime);
            a = 5;
        }
    =}
    reaction(in) {=
        thread_t thread_id;
        pthread_create(&thread_id, NULL, gpu_thread, NULL);
        sleep(ashorttime);
        if (a==0) {
            // Took too long, kill the thread
            return;
        }
        // Do important stuff
    =}
}

This also ties into our previous discussions about pluggable scheduling where an external scheduler is called at certain controlled joints. The preempt keyword would in this case enforce/enable a credit-based scheduler.

@Soroosh129 Soroosh129 added the enhancement Enhancement of existing feature label Feb 12, 2021
@edwardalee
Copy link
Collaborator

This is a really interesting idea. Setjump and longjump are another alternative way to implement this. Both techniques have risks: killing a thread can lead to inconsistencies in memory data structures and/or to memory leaks. Same with setjump and longjump. With disciplined programming, however, they can be made to work.

@edwardalee
Copy link
Collaborator

Another variant of this idea might be to provide clean support for anytime computation. Rather than just terminating the thread that takes too long, we have that thread checkpoint intermediate results. When the expires, we would terminate addition computation, as above, but use the latest checkpoint to provide approximate results.

@edwardalee
Copy link
Collaborator

I think this issue is superseded by #403.

@lhstrh lhstrh added the exclude Exclude from change log label Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing feature exclude Exclude from change log
Projects
None yet
Development

No branches or pull requests

3 participants