linux ϵͳÖе¥¸ö½ø³ÌµÄ×î´óÏß³ÌÊýÓÐÆä×î´óµÄÏÞÖÆ PTHREAD_THREADS_MAX
Õâ¸öÏÞÖÆ¿ÉÒÔÔÚ /usr/include/bits/local_lim.h Öв鿴¡£
¶Ô linuxthreads Õâ¸öÖµÒ»°ãÊÇ 1024£¬¶ÔÓÚ nptl ÔòûÓÐÓ²ÐÔµÄÏÞÖÆ£¬½ö½öÊÜÏÞÓÚϵͳµÄ×ÊÔ´Õâ¸öϵͳµÄ×ÊÔ´Ö÷Òª¾ÍÊÇÏß³ÌµÄ stack ËùÕ¼ÓõÄÄڴ棬Óà ulimit -s ¿ÉÒԲ鿴ĬÈϵÄÏß³ÌÕ»´óС£¬Ò»°ãÇé¿öÏ£¬Õâ¸öÖµÊÇ 8M¡£
¿ÉÒÔдһ¶Î¼òµ¥µÄ´úÂëÑéÖ¤×î¶à¿ÉÒÔ´´½¨¶àÉÙ¸öÏß³Ì
#include <stdio.h> #include <pthread.h>
int main() { int i = 0; pthread_t thread;
while (1) { if (pthread_create(&thread, NULL, foo, NULL) != 0) return; i ++; printf("i = %d\n", i); }
return 0; } |