This section describes special attributes of threads, mutexes, and condition variables. The implementation of these attributes is optional; it depends on POSIX options.
A stack is allocated for each thread. Stack management is implementation-dependent; thus, the following information applies only to AIX, although similar features may exist on other systems.
The stack is dynamically allocated when the thread is created. Using advanced thread attributes, it is possible for the user to control the size and address of the stack. The following information does not apply to the initial thread, which is created by the system.
The stacksize attribute is defined in AIX. It depends on the stack size POSIX option; this option may not be implemented on other systems.
The stacksize attribute specifies the minimum stack size that will be allocated for a thread. The pthread_attr_getstacksize subroutine returns the value of the attribute, and the pthread_attr_setstacksize subroutine sets the value.
The stacksize attribute is used as follows to calculate the size of the stack to allocate:
In the AIX implementation of the threads library, a chunk of data, called user thread area, is allocated for each created thread. The allocation is always a multiple of 4KB. As shown in the following figure, the area is divided into:
Note: The user thread area described here has nothing to do with the uthread structure used in the AIX kernel. The user thread area is accessed only in user mode and is exclusively handled by the threads library, whereas the uthread structure only exists within the kernel environment.
The stackaddr attribute is not defined in AIX. It depends on the stack address POSIX option; this option is not implemented in AIX but may be implemented on other systems.
The stackaddr attribute specifies the address of the stack that will be allocated for a thread. The pthread_attr_getstackaddr subroutine returns the value of the attribute, and the pthread_attr_setstackaddr subroutine sets the value.
If no stack address is specified, the stack is allocated by the system at an arbitrary address. There is no way to get this address. Usually you do not need to know the stack address. However, if you really need to have the stack at a known location, you can use the stackaddr attribute. For example, if you need a very large stack, you may set its address to an unused segment, guaranteeing that the allocation will succeed.
If a stack address is specified when calling the pthread_create subroutine, the system will try to allocate the stack at the given address. If it fails, the pthread_create subroutine returns EINVAL. The pthread_attr_setstackaddr subroutine never returns an error, unless the specified stack address exceeds the addressing space, because it does not actually allocate the stack.
Most UNIX systems allow several processes to share a common data space, known as shared memory. AIX also provides this facility; see Understanding Memory Mapping for more information about the AIX shared memory facility. The process sharing attributes for condition variables and mutexes are meant to allow these objects to be allocated in shared memory to support synchronization among threads belonging to different processes. However, there is no industry-standard interface for shared memory management. For this reason, the process sharing POSIX option is not implemented in the AIX threads library.
Making Complex Synchronization Objects.
List of Threads Advanced Feature Subroutines.