https://bugs.winehq.org/show_bug.cgi?id=57035
--- Comment #4 from LIU Hao lh_mouse@126.com --- (In reply to Zeb Figura from comment #3)
Does POSIX guarantee that if a process sleeps until absolute time X, that its next query for time will be greater than or equal to X? It's not clear to me whether clock_nanosleep() actually guarantees this.
If process A sleeps until absolute time X, wakes up process B, and process B checks time, is it guaranteed to be greater than or equal to X?
If process A gets time X, sleeps for C ms, then wakes up process B, does B get at least X+C?
This sounds to me like a question that, if `clock_nanosleep()` has exceeded an absolute time point, is a subsequent call to `clock_gettime` allowed to return a value less than the argument to `clock_nanosleep`?
The last one is the situation we're dealing with here (process A is wineserver; C is correctly calculated to always round up). If POSIX guarantees this, then it's a host (Linux) bug. If POSIX does not guarantee this, then I don't think there's anything we can do.
This is clearly not a host issue. There is no such issue on Wine 6 on Linux Mint 21 but there is such an issue on Wine 9 on the same system.
And on my current Linux Mint 22 (bug) installation I create this program to test the host system:
```c // x86_64-linux-gnu-gcc test.c -Wall -Wextra -O2 #include <pthread.h> #include <time.h> #include <stdio.h>
int main(void) { struct timespec t1, t2;
// Get current time and round up to a one-second boundary. clock_gettime(CLOCK_REALTIME, &t1); t1.tv_sec += 2; t1.tv_nsec = 0;
// Wait for the current process itself (effectively sleep). printf("sleep until %ld\n", t1.tv_sec * 1000000000 + t1.tv_nsec); clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &t1, NULL);
// Check current time. clock_gettime(CLOCK_REALTIME, &t2); printf("current time %ld\n", t2.tv_sec * 1000000000 + t2.tv_nsec); } ```
and `clock_nanosleep` never resumes prematurely:
``` lh_mouse@lhmouse-xps ~/Desktop $ x86_64-linux-gnu-gcc test.c -Wall -Wextra -O2
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out sleep until 1722915802000000000 current time 1722915802000076765
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out sleep until 1722915804000000000 current time 1722915804000115219
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out sleep until 1722915806000000000 current time 1722915806000087441
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out sleep until 1722915808000000000 current time 1722915808000032686
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out sleep until 1722915810000000000 current time 1722915810000037128 ```