Jump to content

How SC_FORK and SC_JOIN implemented ?


saraswathi.m

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?

 

Link to comment
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

Link to comment
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 ?

Link to comment
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

Link to comment
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 ?

Link to comment
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 ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...