Jump to content

Pratik Parvati

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by Pratik Parvati

  1. Hi team,

    I have a small piece of code inked below. 

    #include <systemc.h>
    #include <iostream>
    
    using namespace std;
    
    class Test: public sc_module
    {
    private:
        sc_event e1;
    public:
        SC_HAS_PROCESS(Test);
        Test(sc_module_name nm): sc_module(nm), SC_NAMED(e1)
        {
            SC_THREAD(th1);
    
            SC_THREAD(th2);
            SC_THREAD(th3);
        }
    
        void th1()
        {
            wait(e1);
            cout << "Test::th1() --> event e1 notified" << endl;
        }
    
        void th2()
        {
            e1.notify();
            cout << "Test::th2() --> event has been notified" << endl;
        }
    
        void th3()
        {
            cout << "Test::th3() --> waiting for event e1" << endl;
            wait(e1);
            cout << "Test::th3() --> event e1 notified" << endl;
        }
    
    };
    
    int sc_main(int argc, char* argv[])
    {
      Test t("test");
      sc_start(10, SC_NS);
    }

    The above code prints

    Test::th2() --> event has been notified
    Test::th3() --> waiting for event e1
    Test::th1() --> event e1 notified

    I understand that using immediate notification is not encouraged in SystemC (as there are chances that some processes might miss the notified event). But from the above output when event in th2 is notified the SystemC scheduler schedules th3 (after return statement of th2); the statement before wait(e1) is displayed but not after the wait. 

    Also if you observe , the statement after wait in th1 is displayed correctly and th1 is scheduled first when simulation starts.

    So, my understanding is - Since th1 thread is waiting for e1 before e1.notify() (in th2); th1 is considered to schedule in the same evaluation phase and th3 has missed this event; to resolve this I should replace e1.notify() with e1.notify(SC_ZERO_TIME). 

    If my understanding is correct, What is reason behind this behaviour?

×
×
  • Create New...