Jump to content
TRANG

sc_spawn and anthoer process

Recommended Posts

sc_spawn allows to create process during simulation runtime.  SC_* macro can be used only at elaboration time. Please read more details in IEEE SystemC standard.

Here is small usage example:

#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc.h>

SC_MODULE(spawn_demo) {

    SC_CTOR(spawn_demo) {
        SC_THREAD(static_thread);
    }

    void static_thread() {
        sc_spawn_options opts;
        sc_spawn([&]() {
            wait(1, SC_NS);
            cout << "spawned @ " << sc_time_stamp() << "\n";
            }, "spawned_thread", &opts);

        wait(1, SC_NS);
        cout << "static @ " << sc_time_stamp() << "\n";
    }
};

int sc_main(int argc, char **argv) {
    spawn_demo demo0{"demo0"};
    sc_start();
    return 0;
}

 

Share this post


Link to post
Share on other sites

sc_spawn creates same kind of processes as sC_METHOD, SC_THREAD, etc, but is not limited to the elaboration phase. Please either read the official documentation for IEEE-1666 (available as pdf free via Accellera) or get a good book on SystemC or take a class.

 

Share this post


Link to post
Share on other sites
On 6/15/2018 at 12:56 AM, Roman Popov said:

sc_spawn allows to create process during simulation runtime.  SC_* macro can be used only at elaboration time. Please read more details in IEEE SystemC standard.

Here is small usage example:


#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc.h>

SC_MODULE(spawn_demo) {

    SC_CTOR(spawn_demo) {
        SC_THREAD(static_thread);
    }

    void static_thread() {
        sc_spawn_options opts;
        sc_spawn([&]() {
            wait(1, SC_NS);
            cout<< "spawned @ " << sc_time_stamp() << "\n";
            }, "spawned_thread", &opts);

        wait(1, SC_NS);
        cout<< "static @ " << sc_time_stamp() << "\n";
    }
};

int sc_main(int argc, char **argv) {
    spawn_demo demo0{"demo0"};
    sc_start();
    return 0;
}

 

This is it means: sc_spawn can use for function have parameter and SC_* it not. Right or wrong?

Share this post


Link to post
Share on other sites
41 minutes ago, Hook said:

This is it means: sc_spawn can use for function have parameter and SC_* it not. Right or wrong?

If you want to pass a parameter to process, then you can use sc_spawn and std::bind to bind parameters.

Share this post


Link to post
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...