Debian Bug report logs - #1000978
datefudge: fails to adjust pthread_cond_timedwait()

version graph

Package: datefudge; Maintainer for datefudge is Robert Luberda <[email protected]>; Source for datefudge is src:datefudge (PTS, buildd, popcon).

Reported by: Anders Kaseorg <[email protected]>

Date: Thu, 2 Dec 2021 02:15:02 UTC

Severity: normal

Found in version datefudge/1.24

Reply or subscribe to this bug.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to [email protected], Robert Luberda <[email protected]>:
Bug#1000978; Package datefudge. (Thu, 02 Dec 2021 02:15:04 GMT) (full text, mbox, link).


Acknowledgement sent to Anders Kaseorg <[email protected]>:
New Bug report received and forwarded. Copy sent to Robert Luberda <[email protected]>. (Thu, 02 Dec 2021 02:15:04 GMT) (full text, mbox, link).


Message #5 received at [email protected] (full text, mbox, reply):

From: Anders Kaseorg <[email protected]>
To: "[email protected]" <[email protected]>
Subject: datefudge: fails to adjust pthread_cond_timedwait()
Date: Thu, 2 Dec 2021 02:05:17 +0000
Package: datefudge
Version: 1.24

The test programs below should sleep for 2 seconds. However, under datefudge '1 second', they actually sleep for 3 seconds, and under datefudge '1 second ago', they only sleep for 1 second. This seems to be because datefudge adjusts the clock_gettime() call, but not the pthread_cond_timedwait() call or the futex() call that implements it.

I noticed this while using threading.Thread.join(timeout) in Python 3.6. (Python 3.8 has since changed that to use CLOCK_MONOTONIC: https://bugs.python.org/issue12822.)

First test program, using pthread_cond_timedwait() (compile with gcc -pthread):

#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main() {
  pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_lock(&mutex);
  struct timespec timeout;
  clock_gettime(CLOCK_REALTIME, &timeout);
  timeout.tv_sec += 2;
  printf("sleeping\n");
  pthread_cond_timedwait(&cond, &mutex, &timeout);
  printf("done\n");
  return 0;
}

Second test program, using futex() directly:

#include <linux/futex.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>

int main() {
  uint32_t u = 123;
  struct timespec timeout;
  clock_gettime(CLOCK_REALTIME, &timeout);
  timeout.tv_sec += 2;
  printf("sleeping\n");
  syscall(SYS_futex, &u, FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME, 123,
          &timeout, FUTEX_BITSET_MATCH_ANY);
  printf("done\n");
  return 0;
}



Send a report that this bug log contains spam.


Debian bug tracking system administrator <[email protected]>. Last modified: Tue May 13 15:30:07 2025; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU General Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.