469,320 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

Question about fprintf

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[i],&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
Aug 18 '08 #1
3 3567
On 18 Aug, 11:02, vamsi <vamsi.kom...@gmail.comwrote:
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[i],&attr,func,NULL);
what is i at this point? is &p[i] 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

--
Nick Keighley
Aug 18 '08 #2
On Aug 18, 3:11 pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 18 Aug, 11:02, vamsi <vamsi.kom...@gmail.comwrote:
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[i],&attr,func,NULL);

what is i at this point? is &p[i] 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

--
Nick Keighley
i=0; even then it dumps core. I shall try posting in other groups as
well.
Aug 18 '08 #3
In article <6b**********************************@v1g2000pra.g ooglegroups.com>,
vamsi <va**********@gmail.comwrote:
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
--
Please remember to mention me / in tapes you leave behind.
Aug 18 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andrew Fabbro | last post: by
7 posts views Thread by jchludzinski | last post: by
6 posts views Thread by QQ | last post: by
1 post views Thread by QQ | last post: by
2 posts views Thread by canteyn | last post: by
8 posts views Thread by sore eyes | last post: by
83 posts views Thread by Bill Cunningham | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.