Jump to content

sc_vector and thread processes


Recommended Posts


I would like to create an arbitrary (random) number of processes, of the same module. So I tried with sc_vector.

I can instantiate sc_module but not when there is a SC_THREAD in the module.

I have the following code in my header "nodes.h"

struct CNodes : sc_core::sc_module
    CNodes(sc_core::sc_module_name instance);
    ~CNodes(void) = default;
	void CNodes::Init_node(int, float, float);



	int id = 0;
    // Processes and overrides
	void Thread_node(void);

And the cpp files is :

#include "Nodes.h"

CNodes::CNodes(sc_core::sc_module_name instance)
	id = 0;
	std::cout << "Constructing CNodes " << std::endl;

void CNodes::Init_node(int pid, float bias, float rate)
{ }

void CNodes::Thread_node(void)
	std::cout << "Hi there" << std::endl;

When I put the "SC_THREAD" macro in my code, I got an error during elaboration

Error: (E549) uncaught exception: Access violation - n
In file: C:\SystemC\src\sysc\kernel\sc_except.cpp:98


The top module is this one. It instantiates 20 objects of class CNodes  :

#include <string>
#include <time.h>
#include "Network.h"

#include "Nodes.h"

using namespace std;

CNetwork::CNetwork (sc_core::sc_module_name name, unsigned _size = 4): sc_core::sc_module(name), nodes("node")
	float bias, rate;

	/* initialize random seed: */
	srand((unsigned int)time(NULL));

	for (unsigned int i = 0; i < nodes.size(); i++)
		// generate random numbers for nodes
		bias = (float)rand() / RAND_MAX;
		rate = (float)rand() / RAND_MAX;
		nodes[i].Init_node(i, bias, rate);

The modules "nodes" will have also ports, etc. But for the moment, I'm stuck with the instantiation. When I remove the problematic line, "SC_THREAD(Thread_node);", it works fine for the moment. But in that case I don't have the processes I need for my model.


Is ther a way to instantiate a arbitrary number of processes, arbitrary meaning that the number is not known during coding phase because it will be random.


Thanks !


Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

I am not sure, but:

with the construction


you say that "I have a thread, that is not sensitive to any event (==cannot be started later), and should not be started at the beginning. Maybe the kernel is not prepared for such a request.

Concerning "to instantiate a arbitrary number of processes": you probably have some upper limit on the number of processes, so you can instantiate that maximum number of modules, and than later you limit the actual (active) modules in the simulation to the random value you generate.

I hope this helps.



Link to comment
Share on other sites

Hello @elibre,

It looks like you need to utilize dynamic processes to achieve what you have mentioned in your query.

You can find necessary details here:

  1. https://forums.accellera.org/topic/6089-sc_spawn-and-anthoer-process/
  2. https://sclive.wordpress.com/2008/01/10/systemc-tutorial-threads-methods-and-sc_spawn/

The second link is slightly dated, but still has details for what you want to achieve.

Hope this helps.


Ameya Vikram Singh

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