Jump to content
wasim6691

Stack Size Overflow due to recursion

Recommended Posts

Hi 

I have 3 to 4 modules and they have 3 to 4 inputs but to synchronize the timing of inputs as they all have to have specific value only then my THREAD PROCESS should run, I am using value_changed_event inside the THREAD PROCESS of the MODULE by using wait(sig.value_changed_event()). But In some MODULES, I am initializing large arrays and due to this when the value changes then it rerun from the 1st Module to the Last and stops in the mid-way displaying the stack over flow as the exception. What Should be the possible solution for this ? I have Increase the Stack size upto  1Giga but still does not work. Thanks 

Share this post


Link to post
Share on other sites

Don't use recursion?

Remember that the stack size applies to each process (SC_THREAD and SC_METHOD), and the machine you are running on needs to have enough memory to accommodate this. If you have 16 threads running with 1G stack, then you need a machine with 16G just for your threads.

Share this post


Link to post
Share on other sites

Hi @wasim6691,

Here is a small set of questions if you can provide some answers it would be helpful:

  • Can you provide details about the development environment?(Linux/Windows)
  • How are you setting up the stack size?
  • Can you modify your code to use dynamically allocated array just for the sake of modelling?

Regards,

Ameya Vikram Singh

Share this post


Link to post
Share on other sites

Hi

1) my Development Environment is Windows with Visual Studio 2013 for Desktop

2) In Visual Studio, You have the option in the Linker--- System--- Setting for Stack and Heap Size

3) Yes, This is the only option to use Dynamically Allocated.

 

But Can You suggest me some other option to get out of this Stack over flow Problem. ? Thanks. 

RECURSION: By recursion I mean that If I am sending input from Module-1 to Module-2 and then I am expecting a result from Module-1 to Module-2 (Here in their processes I am using sig.value_changed_event())  and then after getting the result from Module-1, Module-2 send the input to Module-3. 

Share this post


Link to post
Share on other sites
Quote

But In some MODULES, I am initializing large arrays and due to this when the value changes then it rerun from the 1st Module to the Last and stops in the mid-way displaying the stack over flow as the exception.

Do not put large arrays on process stack. Put them into Module instead, and allocate module in heap.

Example:

Large array on stack:

SC_MODULE(top) {

SC_CTOR(top){
   SC_THREAD(thread);
}

void thread() {
int large_array[1000000000]; // will be allocated on sc_thread stack
}

};

int sc_main(int , char**) {
   top top_inst{"top_inst"};
   sc_start();
}

 

After refactoring:

SC_MODULE(top) {

SC_CTOR(top){
   SC_THREAD(thread);
   int large_array[1000000000]; // inside module body
}

void thread() {
}

};

int sc_main(int , char**) {
   auto top_inst = std::make_unique<top>{"top_inst"}; // allocated on heap
   sc_start();
}

 

 

 

 

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

×