Jump to content

Dynamic process creation using sc_spawn


Recommended Posts


I am not able to think of  the case where we need to create dynamic processes using sc_spwan and cases where simple SC_THREAD/SC_METHOD is not suffice.

Can you give me few example cases where I must use sc_spawn during end_of_elaboration or during simulation to create the processes?

Thanks in advance




Link to comment
Share on other sites

Hi Sumit,

I think when you are just modeling hardware with fixed modules, there probably isn't a whole lot of uses for sc_spawn (I'm sure others could find some uses).  However, in my models, I do a lot of modeling of firmware state machines at a pretty high level of abstraction (ie. I'm writing models before any firmware is available, so the models are not using something like instruction set simulators).  In these models, a command is received and then a number of different actions are taken in sequence throughout the lifetime of the command, sometimes waiting on hardware or other threads, etc.).  The easiest way to model this is as an sc_thread:

void run(Command received_command) {
  wait(10, SC_US);

The thing is, at compile time, I have no idea how many commands I'll receive, this depends on run-time inputs to the model.  So I typically have a fixed module using SC_THREAD receiving the commands, but then for each command it receives, it kicks off a run using sc_spawn.


void receiver() {
 while(true) {
    auto command = fifo.read();
    sc_spawn(sc_bind(&run, command));


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.

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...