This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Unable to create thread with stack on the PowerPC Simulator


Hello!

I have tried to run a C program, which creates 4 threads each with stack size 100000 bytes,
on the PowerPC simulator (the program listing is given below).
I get the following error message:


"ERROR; return code from pthread_create() is 11"

When I use a stack size of 5000 bytes, it works. It looks like there is not enough memory
available. How do I fix it? Does this have something to do with the following macro included
in the .gdbinit file?


define psim target sim -o '/iobus/pal@0xf0001000/reg 0xf0001000 32' rbreak cyg_test_exit rbreak cyg_assert_fail end


Do I have to make modifications here?



Thank you very much in advance.


Kind regards, Vimala Bauer

PS

Here is the C program:

#include <pthread.h>
#include <stdio.h>
#define NTHREADS 4
#define N 1000
#define MEGEXTRA 1000000

pthread_attr_t attr;

void *dowork(void *threadid)
{
  double A[N][N];
  int i,j;
  long tid;
  size_t mystacksize;

  tid = (long)threadid;
  pthread_attr_getstacksize (&attr, &mystacksize);
  printf("Thread %ld: stack size = %li bytes \n", tid, mystacksize);
  for (i=0; i<N; i++)
    for (j=0; j<N; j++)
     A[i][j] = ((i*j)/3.452) + (N-i);
  pthread_exit(NULL);
}

int main(int argc, char *argv[])
{
  pthread_t threads[NTHREADS];
  size_t stacksize;
  int rc;
  long t;

  pthread_attr_init(&attr);
  pthread_attr_getstacksize (&attr, &stacksize);
  printf("Default stack size = %li\n", stacksize);
  stacksize = sizeof(double)*N*N+MEGEXTRA;
  printf("Amount of stack needed per thread = %li\n",stacksize);
  pthread_attr_setstacksize (&attr, stacksize);
  printf("Creating threads with stack size = %li bytes\n",stacksize);
  for(t=0; t<NTHREADS; t++){
     rc = pthread_create(&threads[t], &attr, dowork, (void *)t);
     if (rc){
        printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(-1);
     }
  }
  printf("Created %ld threads.\n", t);
  pthread_exit(NULL);
}



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]