I have a small piece of code inked below.
using namespace std;
class Test: public sc_module
Test(sc_module_name nm): sc_module(nm), SC_NAMED(e1)
cout << "Test::th1() --> event e1 notified" << endl;
cout << "Test::th2() --> event has been notified" << endl;
cout << "Test::th3() --> waiting for event e1" << endl;
cout << "Test::th3() --> event e1 notified" << endl;
int sc_main(int argc, char* argv)
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?