Question about fprintf

V

vamsi

Hi,

I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size). There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.

code snippet :
*********************************************************************************
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);

#define OUTSTREAM stderr

pthread_attr_t attr;
main()
{
pthread_t p[10];
void *exitstatus;
int i;
pthread_attr_init(&attr);
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nfailed to set stack size");
}
pthread_create(&p,&attr,func,NULL);

sleep(1000);

}
void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");
}

core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1 0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2 0x008da40f in fprintf () from /lib/tls/libc.so.6
#3 0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4 0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5 0x0095efee in clone () from /lib/tls/libc.so.6

*********************************************************************************
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp

Please help me.

Thanks in advance
Vamsi
 
N

Nick Keighley

I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size).

and at that point you left the realm of standard C.
Standard C has no threads or stacks. Uou nedd to try
a Unix(?) group.

There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.

code snippet :
***************************************************************************­******
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);

#define OUTSTREAM stderr

pthread_attr_t attr;
main()
{
        pthread_t p[10];
        void *exitstatus;
        int i;
        pthread_attr_init(&attr);
        if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
        {
                printf("\n\n\nfailed to set stack size");
        }
        pthread_create(&p,&attr,func,NULL);


what is i at this point? is &p a valid location?
        sleep(1000);

}

void func(void *ptr)
{
        int i ;
        char str[100];
        fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");

}

core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0  0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1  0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2  0x008da40f in fprintf () from /lib/tls/libc.so.6
#3  0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4  0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5  0x0095efee in clone () from /lib/tls/libc.so.6

***************************************************************************­******
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp
 
V

vamsi

I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size).

and at that point you left the realm of standard C.
Standard C has no threads or stacks. Uou nedd to try
a Unix(?) group.


There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.
code snippet :
***************************************************************************­******
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void func(void *);
#define OUTSTREAM stderr
pthread_attr_t attr;
main()
{
pthread_t p[10];
void *exitstatus;
int i;
pthread_attr_init(&attr);
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))
{
printf("\n\n\nfailed to set stack size");
}
pthread_create(&p,&attr,func,NULL);


what is i at this point? is &p a valid location?




sleep(1000);

void func(void *ptr)
{
int i ;
char str[100];
fprintf(OUTSTREAM," FIRST :: Thread Created and here is fprintf
\n");

core dump trace in gdb:
Starting program: /users/a21313/fprintf/ftest_clean
[Thread debugging using libthread_db enabled]
[New Thread -1208084800 (LWP 32021)]
[New Thread -1207960656 (LWP 32024)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1207960656 (LWP 32024)]
0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
(gdb) bt
#0 0x008d1b06 in buffered_vfprintf () from /lib/tls/libc.so.6
#1 0x008d1deb in vfprintf () from /lib/tls/libc.so.6
#2 0x008da40f in fprintf () from /lib/tls/libc.so.6
#3 0x080485b0 in func (ptr=0x0) at fprintf_thread_clean.c:28
#4 0x00ade341 in start_thread () from /lib/tls/libpthread.so.0
#5 0x0095efee in clone () from /lib/tls/libc.so.6
***************************************************************************­******
If i change stderr to stdout. the fprintf does not dump core.
OS used : Linux 2.6.9-11.ELsmp


i=0; even then it dumps core. I shall try posting in other groups as
well.
 
R

Richard Tobin

vamsi said:
if(pthread_attr_setstacksize (&attr,16ul * 1024ul))

An obvious possibility is that this stack size is too small. Have
you tried other sizes, or using the default size?

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top