Jump to content
saraswathi.m

How SC_FORK and SC_JOIN implemented ?

Recommended Posts

Hi All,

 

How sc_fork and sc_join is internally implemented? in below code control will not come to end of file.

 

SC_MODULE(top) {

       void run() {

            cout " run: before fork/join" << endl;

     

            SC_FORK

            SC_JOIN

   

            cout << "run: after fork/join" << endl;

      }

    SC_CTOR(top) {

        SC_THREAD(run);

     }

};

 

int sc_main(int argc, char **argv) {

      top top_1("top_1);

      sc_start();

      return 0;

}

 

 

Output :

run:before fork/join

 

 

question : why after fork/join is not printed in this case?

 

Share this post


Link to post
Share on other sites

question : why after fork/join is not printed in this case?

 

Quoting from IEEE 1666-2011, 5.5.7 (emphasis mine):

The text between SC_FORK and SC_JOIN shall consist of a series of one or more calls to function sc_spawn separated by commas.

 

Since you don't fork anything, on what do you want to join?

 

/Philipp

Share this post


Link to post
Share on other sites

if i have a spawned process inside fork/join and property is set to dont_initialize. 

 

SC_MODULE(top) {

     

  void fun() {

           cout " =========== fun========" << endl;

}

 

sc_spawn_options opt;

 

  void run() {

            opt.dont_initialize();

            cout " run: before fork/join" << endl;

     

            SC_FORK

               sc_spawn(sc_bind(&top::fun, this), "d1", &opt),      

            SC_JOIN

   

            cout << "run: after fork/join" << endl;

      }

    SC_CTOR(top) {

        SC_THREAD(run);

     }

};

 

int sc_main(int argc, char **argv) {

      top top_1("top_1);

      sc_start();

      return 0;

}

 

output :

 before fork/join

================= fun ===============

 

question :

 i have spawned process inside fork and join still the statement "after fork/join " is not printed.how ?

Share this post


Link to post
Share on other sites

if i have a spawned process inside fork/join and property is set to dont_initialize.

 

Spawning a process without static sensitivity and with dont_initialize set makes no sense.  This process will never be activated and will just be an orphaned zombie.  What are you trying to achieve?

 

An SC_FORK/SC_JOIN block is meant to spawn a set of parallel (sub-)processes, wait for the completion/termination of all of them, and continue the processing of the spawng process afterwards.  Since your spawned process will never complete (since it is never activated in the first place), the SC_JOIN statement will never complete either.

 

output :

 before fork/join

================= fun ===============

 

question :

 i have spawned process inside fork and join still the statement "after fork/join " is not printed.how ?

 

Im somewhat doubt that you actually see the "fun" line printed to your output.  It should not be printed given my answer above.  But your code is not the "real" one anyhow (you're missing some stream operators, for example).  Please always try to post the real code.

 

/Philipp

Share this post


Link to post
Share on other sites

yes "fun" line will not print and Thanks for your explanation regarding fork/join.

 

 

 

/Saraswathi

Hello Sir/Madam,

It is requested that you very carefully look up how SystemC threads

are triggered, specifically sensitivity lists. You have:

SC_CTOR(top) {

        SC_THREAD(run);

 }

So which event is the thread triggered on ? Please note that SystemC

is an event friven simulator. And then, sc_spawn_options do not need

to be used. Why complicate things when there are simpler and more

precise methods to tackle a problem ?

Share this post


Link to post
Share on other sites

Hi Dakupoto,

   every systemc process will run at time 0 regardless of sensitivity. However as Philipp points out, using both dont_initialize() and no sensitivity would cause a process to never run,

 

regards

Alan

Share this post


Link to post
Share on other sites

Hi Dakupoto,

   every systemc process will run at time 0 regardless of sensitivity. However as Philipp points out, using both dont_initialize() and no sensitivity would cause a process to never run,

 

regards

Alan

Dear Sir,

I fully agree with your point. However, it seems a bit peculiar to use an event driven

simulator but not take advantage of the core feature of the tool. Of course the thread

will run at time 0, but then what ?

Share this post


Link to post
Share on other sites

Hi Dakupoto,

  you can still use dynamic sensitivity. For instance a typical TLM2 loosely-timed model would use SC_THREADs with no sensitivity. The events are used dynamically as part of set_and_sync() (for instance),

 

kind regards

Alan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×