pthread_create时, 退出时要记得释放资源. 但有时由于系统限制, 线程数被限制. 解决方法如下:
linux系统中每个线程都拥有独立的栈空间, 可用ulimit -a查看限制大小, 如下:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63437
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 63437
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
stack size (kbytes, -s) 8192
这里显示为8M, 线程数就被这里限制了.改变线程栈大小方法如下:
1. ulimit -s xxx
2. pthread_attr_setstacksize
https://www.cnblogs.com/qq78292959/archive/2012/03/29/2423821.html