VirtualBox

Ticket #6318: t.c

File t.c, 572 bytes (added by Samuel Tardieu, 15 years ago)

Source file t.c which demonstrates the problem

Line 
1#include <inttypes.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <time.h>
5
6uint64_t nano_count()
7{
8 struct timespec t;
9 int ret;
10 ret = clock_gettime(CLOCK_MONOTONIC,&t);
11 if(ret != 0) {
12 fprintf(stderr, "clock_gettime failed\n");
13 exit(2);
14 }
15 return (uint64_t) t.tv_sec * 1000000000 + t.tv_nsec;
16}
17
18int
19main()
20{
21 uint64_t old_nanos = 0;
22 for (;;) {
23 uint64_t nanos = nano_count();
24 if (nanos <= old_nanos) {
25 fprintf(stderr, "!!! Clock is not monotonic: %lu >= %lu\n", old_nanos,
26nanos);
27 exit(1);
28 }
29 old_nanos = nanos;
30 }
31}
32
33

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy