1752666 Members
5738 Online
108788 Solutions
New Discussion юеВ

Pthreads

 
SOLVED
Go to solution
Naveen Chandika
Occasional Advisor

Pthreads

I am new to multi threads and I have written a multi thread application using Pthreads and running it on HP-UX B.11.31 U ia64. It works fine when the number of threads are 8. If I increase the thread to 11, its coredump with the following message on

=============
Pid 29493 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssize
or stack size limit is set too small.

is this related to pthread_attr_setstacksize? I am passing NULL as NULL stack address so I think its using PTHREAD_STACK_MIN.

what is the value of PTHREAD_STACK_MIN?
In limits.h it shows it as 4096 and in unistd.h "define _SC_THREAD_STACK_MIN 432"

Can you please suggest what needs to be increased?
10 REPLIES 10
Steven Schweda
Honored Contributor

Re: Pthreads

> Can you please suggest what needs to be
> increased?

Attention to detail?

> [...] HP-UX B.11.31 U ia64 [...]

You've posted your HP-UX question in a Linux
forum.
Dennis Handly
Acclaimed Contributor
Solution

Re: Pthreads

>If I increase the thread to 11, it coredump with the following message on

I'm not sure why increasing the number should do this.
It would be helpful to debug it and get a stack trace.

>is this related to pthread_attr_setstacksize?

It might be if the stack overflow is on a thread stack.

>I am passing NULL as NULL stack address so I think it's using PTHREAD_STACK_MIN.

Why are you calling pthread_attr_setstacksize(3) if you aren't providing a value? No need to call the attribute functions if you take the default.

>what is the value of PTHREAD_STACK_MIN? In limits.h it shows it as 4096

I think the default thread stack size on Integrity is 256 Kb, half for the user stack.
Naveen Chandika
Occasional Advisor

Re: Pthreads


I tried to debug the stack trace using gdb. every time its crashing at different place in different thread and due to a structure memory getting corrupted. sometimes at the time of freeing the structure memory and sometimes when trying to use some members of the structure. The functionality of the thread works fine when the threads count is 8, with out any crash.

I will try to run the application by increasing the thread stack size to check if its crashing due to thread stack.
Dennis Handly
Acclaimed Contributor

Re: Pthreads

>every time its crashing at different place in different thread and due to a structure memory getting corrupted.

If it is a thread stack overflow, you can determine this easily and it doesn't matter if in different places.

>sometimes at the time of freeing the structure memory and sometimes when trying to use some members of the structure.

If it is on a free, you have likely corrupted the heap. What does your stack trace look like?

>I will try to run the application by increasing the thread stack size to check if its crashing due to thread stack.

Analyzing the registers $sp and $bsp on the first and last frames will tell you if you have an overflow.
Naveen Chandika
Occasional Advisor

Re: Pthreads

Thanks.

The following is the stack trace of the core.
(gdb) where
#0 0x60000000c0126320:0 in pthread_default_rsestacksize_np+0x40 ()
from /usr/lib/hpux32/libpthread.so.1


can you please tell me when is the call to pthread_default_rsestacksize_np() is made?
Naveen Chandika
Occasional Advisor

Re: Pthreads

also can you please tell me in what cases this pthread_default_rsestacksize_np() will give core dump?
Dennis Handly
Acclaimed Contributor

Re: Pthreads

>The following is the stack trace of the core.
(gdb) where
#0 0x60000000c0126320:0 pthread_default_rsestacksize_np+0x40 hpux32/libpthread.so.1

It would help if you provided the whole stack trace.

>can you please tell me when is the call to pthread_default_rsestacksize_np() is made?

Probably in pthread_attr_setstacksize or in pthread_attr_init. That's why the whole stacktrace is needed.

>can you please tell me in what cases this pthread_default_rsestacksize_np() will give core dump?

Only if you give it a bad mutex address?

What version of libpthread do you have, which patch?

>is this related to pthread_attr_setstacksize? I am passing NULL as NULL stack address so I think its using PTHREAD_STACK_MIN.

You aren't allowed to pass in NULL to pthread_attr_setstacksize(3). Are you checking for errors after the call?
And 4096 is probably too small for a stack.

_SC_THREAD_STACK_MIN 432, is just a key to get the current value:
$ getconf _SC_THREAD_STACK_MIN
4096
Naveen Chandika
Occasional Advisor

Re: Pthreads

Thanks for your reply.

Actually there is no call pthread_attr_setstacksize() to set the stack size. NULL is being passed as attribute to pthread_create.

May be this is a stupid question but how is the bad mutex address is related to pthread_default_rsestacksize_np()?

What version of libpthread do you have, which patch?
I think its R11.31_BL2007_1213_5, I got it, by doing strings on libpthread.so.

if this is not correct way to know the patch, Can you please tell me how to check libpthread.so patch?

I will get the complete stack.
Dennis Handly
Acclaimed Contributor

Re: Pthreads

>NULL is being passed as attribute to pthread_create.

Ok, it seems that pthread_create may be calling all of those pthread_attr_* functions to get the defaults.

>how is the bad mutex address is related to pthread_default_rsestacksize_np()?

Oops I confused mutex attributes with thread attributes.

>I think it's R11.31_BL2007_1213_5, I got it, by doing strings on libpthread.so.

Instead of strings, use what(1) but that's not that helpful.

>Can you please tell me how to check libpthread.so patch?

I was expecting a patch ID with what. But it appears it isn't there. Try:
swlist | grep -i pthread