Question about fprintf

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vamsi

    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<pthrea d.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_in it(&attr);
    if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
    {
    printf("\n\n\nf ailed to set stack size");
    }
    pthread_create( &p[i],&attr,func,NUL L);

    sleep(1000);

    }
    void func(void *ptr)
    {
    int i ;
    char str[100];
    fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
    (gdb) bt
    #0 0x008d1b06 in buffered_vfprin tf () 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
  • Nick Keighley

    #2
    Re: Question about fprintf

    On 18 Aug, 11:02, vamsi <vamsi.kom...@g mail.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<pthrea d.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_in it(&attr);
            if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
            {
                    printf("\n\n\nf ailed to set stack size");
            }
            pthread_create( &p[i],&attr,func,NUL L);
    what is i at this point? is &p[i] a valid location?
    >
            sleep(1000);
    >
    }
    >
    void func(void *ptr)
    {
            int i ;
            char str[100];
            fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
    (gdb) bt
    #0  0x008d1b06 in buffered_vfprin tf () 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

    Comment

    • vamsi

      #3
      Re: Question about fprintf

      On Aug 18, 3:11 pm, Nick Keighley <nick_keighley_ nos...@hotmail. com>
      wrote:
      On 18 Aug, 11:02, vamsi <vamsi.kom...@g mail.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<pthrea d.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_in it(&attr);
      if(pthread_attr _setstacksize (&attr,16ul * 1024ul))
      {
      printf("\n\n\nf ailed to set stack size");
      }
      pthread_create( &p[i],&attr,func,NUL L);
      >
      what is i at this point? is &p[i] a valid location?
      >
      >
      >
      >
      >
      sleep(1000);
      >
      }
      >
      void func(void *ptr)
      {
      int i ;
      char str[100];
      fprintf(OUTSTRE AM," 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_vfprin tf () from /lib/tls/libc.so.6
      (gdb) bt
      #0 0x008d1b06 in buffered_vfprin tf () 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.

      Comment

      • Richard Tobin

        #4
        Re: Question about fprintf

        In article <6bcf1c70-3a4e-4cd8-bfea-499bbd028049@v1 g2000pra.google groups.com>,
        vamsi <vamsi.komati@g mail.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.

        Comment

        Working...