Menu

embedded clips, Assertstring and segmentation fault

Faraz
2021-09-13
2021-09-24
  • Faraz

    Faraz - 2021-09-13

    Hey there ,
    I am using embedded clips 6.4 on arm and need to let clips know that time has passed so that at some point the following rule can be executed. ( I believe there is no other way than to assert the (tick) fact every SECOND to make sure clips checks it during the next run ).

    (defrule MAIN::myrule
        (tick)
        ?f1<- (req (time ?t))
        (test (< 60 (- (time) ?t))) ; more than 60 seconds has passed since the req has been created
        =>)
    

    here is my while true loop which replaces the original commandloop function and keeps the engine up and ready. (while other parts assertstring in to the engine.)

        //ENVIRONMENT ALREADY CREATED AS mainEnv
    
        Fact *tick;
        time_t last = 0;
        tick = AssertString(mainEnv, "(tick)");
        RetainFact(tick);
    
        while(1)
        {   
            time_t now = time(NULL);
            if(now > last +1) {
                last = now;
                clock = AssertString(mainEnv, "(tick)");
                RetainFact(tick);
            }
    
            Run(mainEnv, -1);
            ReleaseFact(tick);
            Retract(tick);
        }
    

    So the thing is, every now and then , and mostly (not always) in case of an Assertstring of another fact (from elsewhere- not the loop but some background process which sends messages) , I get segmentation fault and kaboom ! like at the 200th tick.

    Any thoughts on how to approach the whole thing, please ?
    I would really appreciate the response and again THANK YOU MR.RILEY for this incredible design of yours

    ~~~

     
  • Faraz

    Faraz - 2021-09-13

    That "clock =" is meant to be " tick". My bad

     
  • noxdafox

    noxdafox - 2021-09-13

    Yes, if you intend to share an environment across multiple threads, you shall protect it from mutual access of its API.

    From the 1.2 Threads and Concurrency chapter of the Advanced Programming Guidelines:

    Each environment can have at most one thread of execution. The CLIPS internal data structures
    can become corrupted if two CLIPS API calls are executing at the same time for a single
    environment. For example, you can’t have one thread executing rules and another thread
    asserting facts for the same environment without some synchronization between the two threads.

    http://clipsrules.sourceforge.net/documentation/v640/apg.pdf

     
  • Faraz

    Faraz - 2021-09-24

    Oh , thanks for your reply

     
  • Faraz

    Faraz - 2021-09-24

    Oh , thanks for your reply

     
  • Faraz

    Faraz - 2021-09-24

    Oh , thanks for your reply

     
  • Faraz

    Faraz - 2021-09-24

    Oh , thanks for your reply

     

Log in to post a comment.