Friday, April 26, 2013

pthread_attr_setscope example c c++

(pthread_attr_setscope example)

NAME

pthread_attr_getscope, pthread_attr_setscope - get and set the contentionscope attribute (REALTIME THREADS)

SYNOPSIS

[THR TPS] [Option Start] #include <pthread.h>

int pthread_attr_getscope(const pthread_attr_t *restrict
 attr,
       int *restrict
 contentionscope);
int pthread_attr_setscope(pthread_attr_t *
attr, int contentionscope); [Option End]

DESCRIPTION

The pthread_attr_getscope() and pthread_attr_setscope() functions, respectively, shall get and set the contentionscope attribute in the attrobject.
The contentionscope attribute may have the values PTHREAD_SCOPE_SYSTEM, signifying system scheduling contention scope, or PTHREAD_SCOPE_PROCESS, signifying process scheduling contention scope. The symbols PTHREAD_SCOPE_SYSTEM and PTHREAD_SCOPE_PROCESS are defined in the <pthread.h> header.

RETURN VALUE of (pthread_attr_getscope, pthread_attr_setscope )

If successful, the pthread_attr_getscope() and pthread_attr_setscope() functions shall return zero; otherwise, an error number shall be returned to indicate the error.

ERRORS

The pthread_attr_getscope() function may fail if:
[EINVAL]
The value specified by attr does not refer to an initialized thread attribute object.
The pthread_attr_setscope() function may fail if:
[EINVAL]
The value of contentionscope is not valid, or the value specified by attr does not refer to an initialized thread attribute object.
[ENOTSUP]
An attempt was made to set the attribute to an unsupported value.
These functions shall not return an error code of [EINTR].
Example of (pthread_attr_getscope, pthread_attr_setscope )



#include <pthread.h>

pthread_attr_t attr;
pthread_t tid;
void start_routine;
void arg;
int ret;

/* initialized with default attributes */
ret = pthread_attr_init (&tattr);

/* BOUND behavior */
ret =  pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
ret = pthread_create (&tid, &tattr, start_routine, arg);