[PATCH] posix condattr additions to gthread library

Chris Fairles chris.fairles@gmail.com
Tue Sep 16 19:37:00 GMT 2008


The new c++0x standard indicates that in the thread library, monotonic
clocks should be used if available. For pthread condition variables
however, timedwait accepts a timespec which is understood to be from
the "system clock" by default (i.e. the clock id CLOCK_REALTIME). If
you use a monotonic clock (CLOCK_MONOTONIC) to obtain the timespec,
then timedwait will not work unless you use pthread_condattr_setclock
to set the clockid of a pthread_condattr_t to CLOCK_MONOTONIC before
initializing the pthread_cond_t with pthread_cond_init (passing in the
pthread_condattr_t with its clock set to CLOCK_MONOTONIC).

Basically, we have to construct the condition variable like so:

pthread_condattr_t a;
pthread_condattr_init(&a);
pthread_condattr_setclock(&a, CLOCK_MONOTONIC);
pthread_cond_t c;
pthread_cond_init(&c, &a);
pthread_condattr_destroy(&a);

in order to use timespecs out of clock_gettime(CLOCK_MONOTONIC, &ts)
in phread_cond_timedwait.


This patch adds the gthread components to allow this in the libstdc++
thread library (bootstrapped x64_64 linux)

Two new types are required:
__gthread_condattr_t: maps directly to pthread_condattr_t
__gthread_clockid_t: the type of the clock id's CLOCK_REALTIME/MONOTONIC

Four new functions:
__gthread_cond_init(__gthread_cond_t*, __gthread_condattr_t*);
__gthread_condattr_init(__gthread_condattr_t*);
__gthread_condattr_setclock(__gthread_condattr_t*, __gthread_clockid_t);
__gthread_condattr_destroy(__gthread_condattr_t*);

questions? comments? concerns?
Chris
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gthr-condattr.patch.txt
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20080916/285ab7db/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Changelog_gthr_condattr.txt
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20080916/285ab7db/attachment-0001.txt>


More information about the Libstdc++ mailing list