3 ms·
Thread overhead in Linux is 8k Those are weasel words. I assume your 8k figure is 4k kernel stack, and 4k userspace stack. First of all, your kernel may not
by cmccabe 13y ago
Thread overhead in Linux is 8k
Those are weasel words.
I assume your 8k figure is 4k kernel stack, and 4k userspace stack. First of all, your kernel may not even be compiled with 4k stacks. 8k kernel stacks are very common. But even if we assume that you do have a 4k kernel stack, you will never be able to do much useful with a 4k userspace stack.
If you want to use pthreads, the default thread stack size is 2 MB, and the minimum is 16kb. Let me Google that for you. http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_attr_setstacksize.html http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_att...
So the absolute mimimum for your normal C/C++ programmer, who doesn't want to do things like reimplement pthreads, is 20 kb. Even that figure seems suspicious to me because it doesn't take into account things like thread-local data in glibc and various other system libraries.
You will quickly realize that if you want to do "luxurious" things like use standard glibc functions, call recursive functions, and so forth, you need more than 4k of userspace stack. For historical reasons, only the main thread has a growable stack-- all others have a fixed size stack. If you exceed the stack size on a thread, you will get undefined behavior, possibly a security vulnerability or a crash.