pthread_create - smaller default thread stack size (CrCh375)
The default thread stack size on HP-UX is smaller than the default thread stack size on Tru64 UNIX.
On Tru64 UNIX, the default thread stack size increased from 24 KB to 5 MB in Version 5.0. On HP-UX, it is only 64 KB on PA systems and 256 KB on Itanium®-based systems. As a result, multithreaded applications
that run fine on Tru64 UNIX may overflow the smaller thread stack on HP-UX and seg fault.
The thread stacks are also organized differently and it is important to understand these differences when changing the thread stack size.
On Tru64 UNIX, the overflow end of the thread stack contains a warning area followed by a guard area. These two areas can help a multithreaded program detect overflow of a thread's stack. The warning area is a page (or more) that is initially protected to trap writes, but then becomes writable so that it can be used to allow reporting or recovering from the overflow. A guard area is a region of no access memory. When the thread attempts to access a memory location within this region, a memory addressing violation occurs.
On HP-UX, the thread stack has a guard area, but no warning area. Also, on Itanium®-based systems, the thread stack is divided evenly into two stacks: the memory stack, which is the conventional stack used directly by the compiler to store local variables and temporaries, and the register stack, which is used by the processor as backing store for the rotating register file. The two stacks grow towards each other and are separated by the guard area.
The default guard area is PAGESIZE bytes on both platforms. The default page size is 8 KB on Tru64 UNIX and 4 KB on HP-UX.
If the default thread stack size on HP-UX is too small for your application, then increase it or use the heap instead of the stack.
The standard way to increase the thread stack size is to use the pthread_attr_setstacksize function. It sets the thread creation stacksize attribute in a pthread_attr_t object. On Itanium®-based systems, the size is divided evenly between the memory (that is, conventional) stack and the register stack.
You can use the pthread_attr_setrsestacksize_np function to divide the memory and register stacks differently. This function was added in HP-UX 11i v2 update 2. The function sets the register stack portion of the thread stack. The memory stack portion is the remainder.
Applications that use these functions will not be able to take advantage of the performance benefits of the thread cache by default. That is because HP-UX only caches threads with default stack sizes. The defaults can be changed with the pthread_default_stacksize_np and pthread_default_rsestacksize_np functions. See their manpages for more information.
Finally, if your application allocates large objects on the stack, consider allocating them on the heap instead.
||any HP-UX 11i version