[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

General Programming Concepts: Writing and Debugging Programs


Advanced Attributes

This section describes special attributes of threads, mutexes, and condition variables. The implementation of these attributes is optional; it depends on POSIX options. For more information, see Threads Library Options.

Read the following to learn more about advanced attributes:

Stack Attributes

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 Stack Size and address of the stack. See Stack Address for more information. The following information does not apply to the initial thread, which is created by the system.

Stack Size

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. 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.

Stack Address

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.

Process Sharing

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.

Thread Programming Concepts.

Threads Advanced Features.

One-Time Initializations.

Thread-Specific Data.

Making Complex Synchronization Objects.

List of Threads Advanced-Feature Subroutines.

Threads Library Options.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]