Strange Pthread Behavior On IRIX

Discussion in 'C Programming' started by Keith, Jun 25, 2003.

  1. Keith

    Keith Guest

    Hi. Was hoping somebody could try and compile this on their SGI system and see
    if it cores. If it cores, comment out the strcpy, and it will work. Or change
    256->32 and it will work.

    To compile: (not sure if the -D_POSIX_C_SOURCE=199506L is necessary)
    cc -D_POSIX_C_SOURCE=199506L -o test test.c -lpthread

    /********** test.c *******/
    #include <pthread.h>
    #include <stdio.h>
    #include <string.h>

    void* test_func( void* );

    int main() {
    pthread_t test_thread ;
    pthread_create( &test_thread, NULL, test_func, NULL) ;
    pthread_join( test_thread, (void**)NULL);
    return 0 ;
    }

    void* test_func( void* silly ) {

    typedef struct {
    char str[1000] ;
    } MY_TEST ;
    MY_TEST my_test[256];

    if ( 0 ) {
    strcpy( my_test[0].str, "Mooo" ) ;
    }

    fprintf(stderr, "Meow\n");

    return ((void*)NULL) ;
    }
    /***** end test.c ****/
     
    Keith, Jun 25, 2003
    #1
    1. Advertising

  2. Keith

    Keith Guest

    I got this answer off of another forum.

    The test_func() function is placing an automatic variable of size
    256*1000 (about 250KB) on the stack. When added together with the
    other values the compiler wants to place on the stack, it comes
    out to a total of 256048 bytes (with MIPSPro C 7.2.1.3m).

    The default size of an individual Pthread's stack under IRIX is 128KB.
    This is documented on the pthread_attr_setstacksize(3P) man page.

    On the first reference to the stack (saving the value of the gp
    register at 24 bytes above the stack pointer), the program generates
    a reference to unmapped memory (i.e. there's nothing allocated there),
    and you get a segment violation.

    To fix the program one must use pthread_attr_setstacksize(3P) to
    define a sufficiently large stack size for the thread in question.

    The reason that a value of 32 works (and even 127) should be clear
    from the above statement.


    (Keith) wrote in message news:<>...
    > Hi. Was hoping somebody could try and compile this on their SGI system and see
    > if it cores. If it cores, comment out the strcpy, and it will work. Or change
    > 256->32 and it will work.
    >
    > To compile: (not sure if the -D_POSIX_C_SOURCE=199506L is necessary)
    > cc -D_POSIX_C_SOURCE=199506L -o test test.c -lpthread
    >
    > /********** test.c *******/
    > #include <pthread.h>
    > #include <stdio.h>
    > #include <string.h>
    >
    > void* test_func( void* );
    >
    > int main() {
    > pthread_t test_thread ;
    > pthread_create( &test_thread, NULL, test_func, NULL) ;
    > pthread_join( test_thread, (void**)NULL);
    > return 0 ;
    > }
    >
    > void* test_func( void* silly ) {
    >
    > typedef struct {
    > char str[1000] ;
    > } MY_TEST ;
    > MY_TEST my_test[256];
    >
    > if ( 0 ) {
    > strcpy( my_test[0].str, "Mooo" ) ;
    > }
    >
    > fprintf(stderr, "Meow\n");
    >
    > return ((void*)NULL) ;
    > }
    > /***** end test.c ****/
     
    Keith, Jun 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrea M. Segovia
    Replies:
    0
    Views:
    987
    Andrea M. Segovia
    Aug 28, 2003
  2. Carla Tironi Farinati

    Java / Virtual Memory Problem with Irix 6.5

    Carla Tironi Farinati, Jun 29, 2005, in forum: Java
    Replies:
    1
    Views:
    467
    Tjerk Wolterink
    Jun 29, 2005
  3. Evan David Light
    Replies:
    6
    Views:
    481
    David Anderson
    Dec 1, 2003
  4. Roger Davis
    Replies:
    3
    Views:
    1,837
    Roger Davis
    Feb 25, 2005
  5. Nick Hawthorn

    Installing Python 2.3.1 on Irix 6.5

    Nick Hawthorn, Oct 2, 2003, in forum: Python
    Replies:
    2
    Views:
    450
    Michael Hudson
    Oct 2, 2003
Loading...

Share This Page