Object-Oriented Interface
The threads library API provides an object-oriented interface. The programmer manipulates opaque objects using pointers or other universal identifiers.
This ensures the portability of multithreaded programs between systems that implement the threads library and also allows implementation changes between two releases of AIX®, necessitating only that programs be recompiled. Although some definitions of data types may be found in the threads library header file (pthread.h), programs should not rely on these implementation-dependent definitions to directly handle the contents of structures. The regular threads library subroutines must always be used to manipulate the objects.
The threads library essentially uses the following kinds of objects (opaque data types): threads, mutexes, rwlocks, and condition variables. These objects have attributes that specify the object properties. When creating an object, the attributes must be specified. In the threads library, these creation attributes are themselves objects, called threads attributes objects.
The following pairs of objects are manipulated by the threads library:
- Threads and thread-attributes objects
- Mutexes and mutex-attributes objects
- Condition variables and condition-attributes objects
- Read-write locks
An attributes object is created with attributes having default values. Attributes can then be individually modified by using subroutines. This ensures that a multithreaded program will not be affected by the introduction of new attributes or by changes in the implementation of an attribute. An attributes object can thus be used to create one or several objects, and then destroyed without affecting objects created with the attributes object.
Using an attributes object also allows the use of object classes. One attributes object may be defined for each object class. Creating an instance of an object class is done by creating the object using the class attributes object.