Can someone explain me, why when I create new threads with stack bigger than default (using pthread_attr_setstacksize()) i can create more? Each thread has it's own stack, so how bigger stack can cause possibility to create more threads?
I use linux 32bit. When I compile this code without MODIFY_STACK definition I can create 380 threads. When I compile with it, I am able to open about 30000 threads. I want just know, how it is possible. On linux 64bit, MODIFY_STACK doesn't make any difference (stack is bigger by default)
You're giving it an invalid stack size of 20000 and not checking if it returns success or error so there's no telling what it's actually setting the stack size to.
Try 20480, that's an even multiple of an x86 system's page size of 4096.
You should also check what the default thread size actually is on your system; whatever it is, I'm pretty sure 20000 is smaller. It used to be 64K, but may have been expanded a few years ago -- some buggy and piggy but unfortunately popular window managers were overrunning default 64K stacks with no obvious way to fix it, and there was talk of upping it to a meg to accommodate their poor code.
You're also never forcing your threads to join or exit, which can cause undefined behavior.
---------- Post updated at 03:03 PM ---------- Previous update was at 02:40 PM ----------
64-bit linux has a much larger limit regardless of the actual size of the thread stacks because it has 2^32 times more address space to waste. You can waste gigabytes upon gigabytes of virtual memory in a 64-bit system as long as you don't actually try to use it all. You could say the main advantage of a 64-bit system is a much bigger imagination
Last edited by Corona688; 08-12-2010 at 05:55 PM..
This code was just an example. I just wanted to know, why bigger stack can allow to create more threads than default
If you're comparing 64-bit linux to 32-bit linux, you might have missed the explanation I tacked on at the last minute. Otherwise, I think you're just mistaken about your system's default thread size, or having problems with your code that my crystal ball missed.
If you're checking compiled-in constants for the default thread size, keep in mind they're often actually minimums, you should get the default by querying the library at runtime. Try pthread_attr_init then pthread_attr_getstacksize
Last edited by Corona688; 08-12-2010 at 06:26 PM..
Hi Guys,
I'm trying to install Oracle Database on to Oracle Linux 7.6 but when
the database install package checks the OS set-up, it keeps on failing
on the soft limits for the stack. It's default value is 8192 but I'm trying
to set it to 10240.
This is what I added to... (2 Replies)
I have MultiThreaded Application in Linux.
I am Setting the stack size using pthread_attr_setstacksize.
The stack size i set is greter than PTHREAD_STACK_MIN i.e. 16384 bytes for my system.
i am setting the stack size to 17408 bytes, and my application crashes due to insufficient stack size.... (1 Reply)
Hi All,
I have set max stack size as 4KB for my thread, but it always using very less.
So I like to know what is the maximum stack size is used by my thread.
I tried with gcc -fstack-usage command line option, but its not supported by mips.
Kindly suggest me the way to find the max stack... (6 Replies)
I need to know what is the maximum stack size i.e. -Xss my java program is running with.
Is there a way to find that out from inside my java program code and outside of it.
What i am looking for is to read whatever the current set max limit -Xss (stack sie) is for a particular JVM(not... (3 Replies)
Hi,
In Linux how to find out what will be the stack size allocated for a process?
Actually i have to fork n number of processess, and will call exec. I will be execing an executable which is already multithreaded and each thread size is defined. My doubt is how to know if the size of the... (2 Replies)
hi all,
I need to find out the Stack usage of an App which is basically an mpeg4 decoder. We are plannin to port the codec to an RTOS. so is there any way to find out the max stack size while the codec is running?
saTs (1 Reply)