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

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

×