pthread의 스택 크기는 제한되지 않습니다.

pthread의 스택 크기는 제한되지 않습니다.

내 기본 스택 크기(ulimit -s에 따라)는 8192kB이므로 아래 코드를 실행하려고 하면 자연스럽게 세그폴트가 발생합니다. 또한, 당연히 "ulimit -s 9000"을 실행하면 정상적으로 작동합니다. 그러나 "ulimit -s unlimited"를 실행하면 코드 segfault가 다시 발생합니다. 어떤 아이디어가 있나요?

도움이 된다면 커널 4.19.0-6 및 gcc 버전 Debian 8.3.0-6이 포함된 Debian 10을 실행하고 있습니다.

#include <iostream>
#include <unistd.h>
#include <cstdlib>

void* wait_exit(void*)
{
  char bob[8193*1024];
  return 0;
}

int main()
{
  pthread_t t_exit;
  int ret;
  
  if((ret = pthread_create(&t_exit,NULL,wait_exit,NULL)) !=0)
  {
    std::cout<<"Cannot create exit thread: "<<ret<<std::endl;
  }
  std::cout<<"Made thread"<<std::endl;
  sleep(5);
  return 0;
}

답변1

"무제한" 스레드의 경우 x86_64에서는 2MiB만 사용할 수 있으므로 다음을 참조하세요.pthread_create 매뉴얼 페이지:

If the RLIMIT_STACK resource limit is set to "unlimited", a per-architecture value is used 
for the stack size.  Here is the value for a few architectures:

              ┌─────────────┬────────────────────┐
              │Architecture │ Default stack size │
              ├─────────────┼────────────────────┤
              │i386         │               2 MB │
              ├─────────────┼────────────────────┤
              │IA-64        │              32 MB │
              ├─────────────┼────────────────────┤
              │PowerPC      │               4 MB │
              ├─────────────┼────────────────────┤
              │S/390        │               2 MB │
              ├─────────────┼────────────────────┤
              │Sparc-32     │               2 MB │
              ├─────────────┼────────────────────┤
              │Sparc-64     │               4 MB │
              ├─────────────┼────────────────────┤
              │x86_64       │               2 MB │
              └─────────────┴────────────────────┘

관련 정보