[v3] c++0x timed wait's in <condition_variable>

Paolo Carlini paolo.carlini@oracle.com
Tue Sep 16 14:08:00 GMT 2008


Hi Chris,

> The pthread_condattr_setclock man page says:
> "The default value of the clock attribute shall refer to the system  
> clock."
>
> At first I was thinking that the realtime system clock
> (CLOCK_REALTIME) is the "system clock" but I'm not convinced since I
> can't find any relation between what POSIX calls the "system clock"
> like in the statement above and CLOCK_REALTIME.
>
> It may be conincedence that the realtime clock and the "system clock"
> have the same epoch and that's why it works. Not robust at all however
> the following test passes on my machine:
>
> #include <cassert>
> #include <pthread.h>
> int main()
> {
>  pthread_condattr_t a;
>  clockid_t c;
>  pthread_condattr_init(&a);
>  pthread_condattr_getclock(&a, &c);
>  assert(c == CLOCK_REALTIME);
>  return 0;
> }

Ok..

> The c++0x WD states that the thread library should use monotonic
> clocks wherever it can (n2723, 30.1.4 p2) so solution B here is only
> temporary anyway.

Ah, this is important.

> The gthread changes are minimal yes. A new type, __gthread_condattr_t,
> and 3 functions __gthread_condattr_init/setclock/destroy. One issue is
> that CLOCK_REALTIME/MONOTONIC are suppose to be of type "clockid_t" so
> I guess we need a __gthread_clockid_t as well. So 2 types and 3
> functions.
>
> I'd rather go for the gthread solution so I can dial up a patch for
> that if you agree.

Sure. Please make sure to post it in a separate thread, a minimum of  
rationale, CC Mark, maybe he will agree that this minor addition can  
be considered a small fix to the now established C++0x gthread  
facililties...

> All this being said, I still think monotonic_clock should be separate
> from system_clock because in our current setup, its impossible to get
> a non-monotonic clock when _GLIBCXX_USE_CLOCK_MONOTONIC is defined.
> The standard isn't very clear on this ... it says monotonic_clock's
> is_monotonic must be true, yet it can be a synonym for system_clock
> and system_clock's is_monotonic is unspecified. This confuses me.

I agree, well we are not alone about this type of confusion, I think,  
did you notice DR 859? Should be resolved here in S Francisco, high  
priority. If you think however, that this specific confusion is  
unrelated to 859, please send a DR to the attention of Howard (howard.hinnant@gmail.com 
), or you can send him an email anyway meant to be a comment to 859.

By the way, I was about to point you to the Rationale section of  
POSIX, about our issue. I would not call it easy material ;) If didn't  
read it yet maybe could be the right time: the section is called  
"Rationale for the Monotonic Clock", in:

   http://www.opengroup.org/onlinepubs/009695399/xrat/xsh_chap02.html

Paolo.



More information about the Libstdc++ mailing list