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

Hi,

        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:
http://freebsd.1045724.n5.nabble.com/pthread-cond-timedwait-broken-in-9-stable-from-JAN-10-td5487565.html

        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,

Cheers

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;
		res->tv_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);

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

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

	pthread_mutex_destroy(&lock);
	pthread_cond_destroy(&cond);

	return EXIT_SUCCESS;
}

Reply via email to