bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: thread stack size


From: Bruno Haible
Subject: Re: thread stack size
Date: Sat, 24 Oct 2009 16:04:01 +0200
User-agent: KMail/1.9.9

Pádraig Brady wrote:
> +       * lib/copy-file.c (copy_file_preserving): Used a 32KiB malloced 
> buffer.

Fine with me too. Yes, 32 KB is more than you can safely allocate on the stack
in a multithreaded program: The default thread stack size is:
  - glibc i386, x86_64    7.4 MB
  - Tru64 5.1             5.2 MB
  - Cygwin                1.8 MB
  - Solaris 7..10           1 MB
  - MacOS X 10.5          460 KB
  - AIX 5                  98 KB
  - OpenBSD 4.0            64 KB
  - HP-UX 11               16 KB

And the default stack size for sigaltstack, SIGSTKSZ, is
  - only 16 KB on some platforms: IRIX, OSF/1, Haiku.
  - only 8 KB on some platforms: glibc, NetBSD, OpenBSD, HP-UX, Solaris.
  - only 4 KB on some platforms: AIX.

Bruno


=============== Program for determining the default thread stack size =========
#include <alloca.h>
#include <pthread.h>
#include <stdio.h>
void* threadfunc (void*p) {
  int n = 0;
  for (;;) {
    printf("Allocated %d bytes\n", n);
    fflush(stdout);
    n += 128;
    *((volatile char *) alloca(128)) = 0;
  }
}

int main()
{
  pthread_t thread;
  pthread_create(&thread, NULL, threadfunc, NULL);
  for (;;) {}
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]