Operating System - Linux
1753637 Members
5914 Online
108798 Solutions
New Discussion юеВ

Size of function stack in threads

 
Miguel Sanchez_2
Occasional Advisor

Size of function stack in threads

Hi,

I have a C++ program running on HPUX 11. It uses Bison to create a parser. The parser function creates the parser stack as a local variable, the default size of the parser stack is about 300K. The program is connected to a message bus. When a message arives (a signal) a callback function calls the parser function.
One of the third-party libraries used to link the program was upgraded so that in order to relink the program I need to include the pthread library. The program itself has not changed and remeins a single thread program, but now linked with the multithread library pthread.
Since that the program chrashed regularly. So I changed size of the bison parser so that the local variable within the parser function has a size of about 5K, and the program runs now pretty stable.
My question: is there any additional limitation in the size of the function stack when using the pthread library?

Thanks in advance,
Miguel
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Size of function stack in threads

Hi Miguel:

You could reconfigure the kernel's 'maxdsiz' or 'maxdsiz_64bit' for 32-bit and 64-bit processes respectively. This would allow you to increase back the parser stack size.

See here fore more information:

http://docs.hp.com/en/TKP-90202/index.html

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Size of function stack in threads

The best approach is to ask the box itself.
There are pthread_attr_getstacksize and pthread_attr_setstacksize functions. Man these functions for details.

I'm a little surprised that you knew to adjust this buffer to "fix" your problem. Have you done a stack trace to determine exactly what is going wrong?

Now, go find a hammer and hit yourself over the head. I have written many compilers, interpreters, parsers, and p-engines using yacc over the years and not once have I used a static buffer. Your buffer should be dynamically allocated and expand as it needs to. I'll bet your old 300K value was tremendous overkill and your new 5K is probably less than you may need.
If it ain't broke, I can fix that.