Event generation in systemc -


i trying understand event generation in systemc. found depends on order of thread registration in constructor.

#include <systemc.h>                                                                                                        sc_module(eventtest){                                                           sc_event ev1;         void p1(){            ev1.notify();            ev1.notify(0, sc_ns);                                                                                             }      void p2(){         wait(ev1);         cout<<"ev1 activated @ "<<sc_time_stamp()<<endl;                    wait(ev1);         cout<<"ev1-2 activated @ "<<sc_time_stamp()<<endl;              }     sc_ctor(eventtest){                                                         sc_thread(p1);         sc_thread(p2);                                            }    };        int sc_main(int argc, char *argv[]){                                        eventtest d("d");                                                    sc_start();     return 1; } 

output : ev1 activated @ 0 s

if change in sc_ctor >

sc_thread(p2);  sc_thread(p1); 

then output >

ev1 activated @ 0 s ev1-2 activated @ 0 s 

please tell how order of registration affect event generation?

your code composed of 2 systemc processes (systemc threads or methods called processes), both systemc threads : p1 , p2. executed both during first delta cycle of simulation. however, systemc standard has no guarantee running order of processes in same delta cycle.

  • if p1 executed first, untimed notification event ev1. see 5.10.6 section of ieee std 1666-2011.

    a call member function notify empty argument list shall create immediate notification. , process instances sensitive event shall made runnable before control returned function notify, exception of executing process instance, shall not made runnable due immediate notification regardless of static or dynamic sensitivity

    however, nothing waiting event. notification nothing. p1 timed notification. in case, behaviour different :

    a call function notify argument represents non-zero time shall create timed notification @ given time, expressed relative simulation time when function notify called. in other words, value of time argument added current simulation time determine time @ event notified. time argument shall not negative. note—in case of delta notification, processes sensitive event in delta notification phase made runnable in subsequent evaluation phase. in case of timed notification, processes sensitive event @ time event occurs made runnable @ time, future simulation time.

    finally, process p1 ends , p2 executed. first wait suspend process. pending notification of event propagated , unlock process p2. then, process p2 execute second wait , suspend again. nothing notify event, simulation end.

  • if p2 executed first, suspend on first wait. then, p1 executed. first notification. p2 waiting notification, p1 suspended (immediate notification) , p2 continue , move on until second wait. p2 suspended. then, p1 continue. timed notification , process ends. p2 waiting notification , happened, p2 execution continue , process ends. simulation ends too.

finally, in 2 cases, p1 executed after p2 systemc implementation used. implementation of systemc, reverse. should consider they're executed in parallel @ same simulation time. in case, both orders right.

in end, means code can lead non deterministic behaviour.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -