는 pthread_create(3)에 대한 맨 페이지가 말한대로 다음 RLIMIT_STACK
자원 제한 (ulimit -s
)를 설정하지 않는 한
, "리눅스/x86-32에 , 새 스레드의 기본 스택 크기는 2메가바이트입니다"에 그 경우 "새 스레드"의 기본 스택 크기를 결정합니다.
다음과 같은 프로그램으로,
getrlimit(2)와 RLIMIT_STACK의 현재 값을 검색하여이 사실을 확인할 수 있습니다
: 그것을 실행하려고 명령 줄에서 (a.out
로 컴파일)시
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
int main()
{
/* Warning: error checking removed to keep the example small */
pthread_attr_t attr;
size_t stacksize;
struct rlimit rlim;
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &stacksize);
getrlimit(RLIMIT_STACK, &rlim);
/* Don't know the exact type of rlim_t, but surely it will
fit into a size_t variable. */
printf("%zd\n", (size_t) rlim.rlim_cur);
printf("%zd\n", stacksize);
pthread_attr_destroy(&attr);
return 0;
}
이러한 결과는 :
$ ulimit -s
8192
$ ./a.out
8388608
8388608
$ ulimit -s unlimited
$ ./a.out
-1
2097152
$ ulimit -s 4096
$ ./a.out
4194304
4194304
이 외에도 linux는 필요에 따라 스택을 자동으로 늘립니다.하지만 이러한 한계에 국한되지 않고 성장할 수있는 영역에서 사용 가능한 주소 공간의 한계도 있습니다. – nos
nos, 메인 스레드 전용, 그렇지 않습니까? – osgx