[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#673711: kfreebsd-9: pthread_cond_timedwait returns immediately with ETIMEDOUT

Package: kfreebsd-image-9.0-1-amd64
Version: 9.0-3
Severity: important
File: kfreebsd-9
Tags: upstream


	when using pthread_cond_timedwait, it often returns immediately with
the error ETIMEDOUT regardless to the length of the timeout passed to the
function. I have provided a C program that illustrates the problem.

	It affects the upstream version (obtained by kfreebsd-downloader).
I have found a thread that, I believe, discusses about the issue:

	I would normally not report the bug since it seems already reported
upstream. However, I stumbled into this problem while I was trying to fix an
RC-bug (#673681) and according to the linked thread, there might be a small
patch that could fix the issue.

Thanks for considering the problem,


Nicolas Bourdaud

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 9.0-RELEASE
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash

Versions of packages kfreebsd-image-9.0-1-amd64 depends on:
ii  devd           9.0+ds1-4
ii  freebsd-utils  9.0+ds1-4
ii  kbdcontrol     9.0+ds1-4
ii  kldutils       9.0+ds1-4

kfreebsd-image-9.0-1-amd64 recommends no packages.

kfreebsd-image-9.0-1-amd64 suggests no packages.

-- no debconf information
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>

#define DELTA	400000000	//400ms
#define NS_PER_MS	1000000
#define NS_PER_SEC	1000000000

void addtime(struct timespec* res, struct timespec* ref, long delta)
	res->tv_sec = ref->tv_sec;
	res->tv_nsec = ref->tv_nsec + delta;
	if (res->tv_nsec >= NS_PER_SEC) {
		res->tv_nsec -= NS_PER_SEC;

int main(void)
	int i;
	struct timespec ts, to;
	pthread_mutex_t lock;
	pthread_cond_t cond;

	pthread_mutex_init(&lock, NULL);
	pthread_cond_init(&cond, NULL);

	for (i=0; i<10; i++) {
		clock_gettime(CLOCK_REALTIME, &ts);
		printf("start: sec:%li  msec:%li\n", (long)ts.tv_sec, ts.tv_nsec/NS_PER_MS);
		addtime(&to, &ts, DELTA);

		while (pthread_cond_timedwait(&cond, &lock, &to) != ETIMEDOUT);

		clock_gettime(CLOCK_REALTIME, &ts);
		printf("end: sec:%li  msec:%li\n", (long)ts.tv_sec, ts.tv_nsec/NS_PER_MS);



Reply to: