Jump to content
Sign in to follow this  
SumitK

Dynamic process creation using sc_spawn

Recommended Posts

Hi 

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

Thanks

Sumit

 

Share this post


Link to post
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) {
  do_x(received_command);
  wait(10, SC_US);
  do_y(received_command);
  mutex.lock();
  do_z(received_command);
  mutex.unlock();
  ...
}

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.

SC_THREAD(receiver);

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

 

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
Sign in to follow this  

×