Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 12.4 Synchronization Attributes 441


clock IDs listed in Figure6.8. Wecan use thepthread_condattr_getclockfunction
to retrieve the clock ID that will be used by thepthread_cond_timedwaitfunction
for the condition variable that was initialized with thepthread_condattr_tobject.
We can change the clock ID with thepthread_condattr_setclockfunction.
#include <pthread.h>

int pthread_condattr_getclock(const pthread_condattr_t *
restrict attr,
clockid_t *restrictclock_id);

int pthread_condattr_setclock(pthread_condattr_t *attr,
clockid_tclock_id);

Both return: 0 if OK, error number on failure

Curiously,the Single UNIX Specification doesn’t define theclockattribute for any of
the other attribute objects that have a wait function with a timeout.

12.4.4 Barrier Attributes


Barriers have attributes, too.We can use thepthread_barrierattr_initfunction
to initialize a barrier attributes object and the pthread_barrierattr_destroy
function to deinitialize a barrier attributes object.
#include <pthread.h>

int pthread_barrierattr_init(pthread_barrierattr_t *attr);

int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);

Both return: 0 if OK, error number on failure

The only barrier attribute currently defined is theprocess-sharedattribute, which
controls whether a barrier can be used by threads from multiple processes or only from
within the process that initialized the barrier.Aswith the other attribute objects, we
have one function to get the attribute (pthread_barrierattr_getpshared)value
and one function to set the value (pthread_barrierattr_setpshared).
#include <pthread.h>

int pthread_barrierattr_getpshared(const pthread_barrierattr_t *
restrict attr,
int *restrict pshared);

int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr,
int pshared);

Both return: 0 if OK, error number on failure
Free download pdf