pthread_attr_getweight_np() — Get weight of thread attribute object
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX | both | POSIX(ON)
|
Format
#define _OPEN_THREADS
#define _OPEN_SYS
#include <pthread.h>
int pthread_attr_getweight_np(pthread_attr_t *attr);
General description
Obtains
the current weight of the thread setting of the thread attributes
object, attr. The symbols for weight are
defined in the pthread.h include file. The following weights are supported:
- __MEDIUM_WEIGHT
- The executing task can be reused when the thread exits.
- __HEAVY_WEIGHT
- When this exits, the associated MVS™ task can no longer request threads to process.
You can use a thread attribute object to manage the characteristics of threads in your application. It defines the set of values to be used for the thread during its creation. By establishing a thread attribute object, you can create many threads with the same set of characteristics, without defining those characteristics for each and every thread. You can define more than one thread attribute object.
Returned value
If successful, pthread_attr_getweight_np() returns the value of the weight of the thread attribute.
If unsuccessful, pthread_attr_getweight_np() returns -1.
There are no documented errno values. Use perror() or strerror() to determine the cause of the error.
Example
CELEBP09
/* CELEBP08 */
#define _OPEN_THREADS
#define _OPEN_SYS /* Needed to identify __HEAVY_WEIGHT AND
__MEDIUM WEIGHT */
#include <stdio.h>
#include <pthread.h>
int main()
{
pthread_attr_t attr;
char weight[12];
if (pthread_attr_init(&attr) == -1) {
perror("error in pthread_attr_init");
exit(1);
}
switch(pthread_attr_getweight_np(&attr)) {
default:
perror("error in pthread_attr_getweight_np()");
exit(2);
case __HEAVY_WEIGHT:
strcpy(weight, "heavy");
break;
case __MEDIUM_WEIGHT:
strcpy(weight, "medium");
}
printf("The thread weight is %s.\n", weight);
if (pthread_attr_destroy(&attr) == -1) {
perror("error in pthread_attr_destroy");
exit(2);
}
exit(0);
}
Output:
The thread weight is heavy.