Linux Thread Stack Size pthread_attr_setstacksize

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. when i set the stack size to 17920 my application runs successfully.

But from my gathered statistics from /proc/<MY PROCESS PID>/task/<TID>/stat , the maximum stack size per thread ( which is the difference of stack pointer and bottom of stack) is not greater than 8KB or 9KB , then why is the process crashing at stack size 17408 bytes i.e. around 16KB.

:wall:

Kindly do clarify my doubts.

Thanking you in anticipation.

Are you sure that's what it really means? That field isn't even documented in proc.txt under the Linux kernel documentation. Obviously if your thread needs more than 16K stack to live, and it's living, it has more than 16K stack...

---------- Post updated at 10:04 AM ---------- Previous update was at 09:52 AM ----------

Incidentally, since memory gets allocated in fixed chunks of 4K or 8K, you're probably not saving anything by giving them 16.01K instead of 20K.