|
Message-ID: <87sfco8b0r.fsf@oldenburg.str.redhat.com> Date: Tue, 25 Apr 2023 13:19:16 +0200 From: Florian Weimer <fweimer@...hat.com> To: Jonathan Wakely <jwakely@...hat.com> Cc: libc-coord@...ts.openwall.com Subject: Re: Relation between C timespec_get time bases and POSIX clockid_t values. * Jonathan Wakely: > C11 added timespec_get and the constant TIME_UTC. POSIX extends this > by requiring TIME_UTC to use the same clock as > CLOCK_REALTIME. However, TIME_UTC is required to be non-zero, and > CLOCK_REALTIME is zero on existing implementations. Uh-oh. | If the timespec_get function is successful it returns the nonzero | value base; otherwise, it returns zero. Here, “base” is TIME_UTC, so that non-zero assumption is baked pretty strongly into the API. This is rather unfortunate. > C23 adds TIME_MONOTONIC, and (optionally supported) TIME_ACTIVE and > TIME_THREAD_ACTIVE. Presumably a future version of POSIX will say > those use the same clocks as CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID > and CLOCK_THREAD_CPUTIME_ID respectively. > > It would be helpful if POSIX guaranteed that every C time base can be > converted to a POSIX clockid_t by adding the constant value (TIME_UTC > - (int)CLOCK_REALTIME). This would allow programs using both > timespec_get and clock_gettime to use a single value for a given > clock, and easily convert to the other domain. For example, a program > using timespec_get in one module (which might be written in portable > ISO C) might want to pass a clock to pthread_cond_timedwait in another > module (written in POSIX C). This could also be relevant to a proposed > C++ extension that would expose the underlying clock used by C++ > clocks such as std::chrono::system_clock and std::chrono::steady_clock > (see https://lists.isocpp.org/std-proposals/2023/04/6379.php for > details). I think the C++ extension should aim at supporting POSIX (plus vendor extensions) exclusively, and ignore the ISO C clocks. C libraries don't know what kind of incompatibilities WG14 will come up next, so we cannot give you any promises for the future behavior of timespec_get. You probably should ignore it. Thanks, Florian
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.