Strange Pthread Behavior On IRIX

K

Keith

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 ****/
 
K

Keith

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.
 

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

Similar Threads

Problem with simple pthread program in C 1
pthread issue 5
pthread error 4
Performance problem with Pthread code 1
about using pthread in cpp 4
pthread memory leaks 15
ld usage 2
pthread problem related to c++ 10

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top