This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
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
Attachment:
gthr-condattr.patch.txt
Description: Text document
Attachment:
Changelog_gthr_condattr.txt
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |