C++ Boost thread attributes set_stack_size

1.6k views Asked by At

I'm trying to find an appropriate value to set a boost::thread's stack size. I'm using the thread to perform recursive operations and was finding that default size was insufficient for my purposes, causing the stack to overflow.

I understand from the boost::thread::attributes documentation that the set_stack_size() function provides a portable interface to underlying platform-specific attributes.

boost::thread::attributes attributes;
std::cout << "DEFAULT: " << attributes.get_stack_size() << std::endl;

On my machine (an MBP running Yosemite / XCode 6.3.2), this prints:

DEFAULT: 524288

I've found that a value of 80,000,000 prevents crashes in all of my test cases. But, I'm not certain that this covers all possible cases and I'm hoping someone can provide some insight about the general design of this feature.

What is the cost of increasing this value? Or, to put it another way, does this setting directly control the amount of memory allocated at runtime or does it merely set some sort of potential upper-bound without actually allocating a huge block of memory from the get-go? From what I can tell so far, increasing this value does not seem to alter my program's memory use. Is this correct? And, would the cost differ by platform?

Thanks for your help!

0

There are 0 answers