Is a compatible implementation in the system impossible without a monotonous clock?

The <chrono> defines the steady_clock class, which is a monotonous clock, that is, the value of now() never decreases as the physical time increases. This class is not marked as optional, but what happens if the implementation cannot implement it because it works in the system without a monotonous time source?

Having looked at the source of libstdC ++, in the case of _GLIBCXX_USE_CLOCK_MONOTONIC it is not defined, steady_clock simply defined:

 typedef system_clock steady_clock; 

system_clock not necessarily stable, so it might (and probably will) violate steady_clock requirements.

Is a compatible C ++ 11 implementation impossible for a system without a monotonous time source? Why not just make steady_clock optional, like intX_t types?

+4
source share
1 answer

I believe that such a system would be some kind of embedded system.

It is good that such systems tomato can have standalone implementations that require only a minimal subset of the standard library. <chrono> not part of this minimal subset.

This is defined in ยง17.6.1.3 Freelance implementations [compliance]:

1 Two types of implementation are defined: hosting and stand-alone (1.4). For a hosted implementation, this International Standard describes a set of available headers.

2 A freelance implementation has a set of headers defined by the implementation. This set should include at least the headings shown in table 16.

Table 16 contains the following headers: <ciso646> , <cstddef> , <cfloat> , <limits> , <climits> , <cstdint> , <cstdlib> , <new> , <typeinfo> , <exception> , <initializer_list> , <cstdalign> , <cstdarg> , <cstdbool> , <type_traits> and <atomic> .

Please note that this does not mean that such an implementation cannot provide the <chrono> header <chrono> everything that can be implemented in it, but not the rest.

+9
source

Source: https://habr.com/ru/post/1447784/


All Articles