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
p1executed first, untimed notification eventev1. 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.
p1timed 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
p1ends ,p2executed. firstwaitsuspend process. pending notification of event propagated , unlock processp2. then, processp2execute secondwait, suspend again. nothing notify event, simulation end.if
p2executed first, suspend on firstwait. then,p1executed. first notification.p2waiting notification,p1suspended (immediate notification) ,p2continue , move on until secondwait.p2suspended. then,p1continue. timed notification , process ends.p2waiting notification , happened,p2execution 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
Post a Comment