Re: [PATCH glibc-2.44] Fix __pthread_timedblock for hurd

Samuel Thibault <[email protected]>
Newsgroups gmane.os.hurd.bugs
Organization I am not organized
Message-ID <aoquVEbmsJrTtDb4@end>
One thing that is a bug, however, is the program below, which stays
blocked because the mach_msg calling loop keeps using the same timeout.

We probably need a version that takes a clock_id and an absolute time,
and does the clock_gettime call itself on each mach_msg calling loop.

Samuel

#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>

void handle(int sig) {
	printf("handle\n");
}

int main(void) {
	pthread_cond_t cond;
	pthread_condattr_t condattr;
	pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
	struct timespec abstime;

	signal(SIGALRM, handle);
	struct itimerval timer = {
		.it_interval = {1, 0},
		.it_value = {1, 0},
	};
	setitimer(ITIMER_REAL, &timer, NULL);

	pthread_condattr_init(&condattr);
	pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
	pthread_cond_init(&cond, &condattr);

	pthread_mutex_lock(&mutex);
	clock_gettime(CLOCK_MONOTONIC, &abstime);
	abstime.tv_sec += 5;
	printf("waiting\n");
	pthread_cond_timedwait(&cond, &mutex, &abstime);
	printf("waited\n");
	pthread_mutex_unlock(&mutex);
	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.