threads/75273: FBSD 5.3 libpthread (KSE) bug
Craig Rodrigues
rodrigc at crodrigues.org
Tue Dec 21 22:10:24 PST 2004
The following reply was made to PR threads/75273; it has been noted by GNATS.
From: Craig Rodrigues <rodrigc at crodrigues.org>
To: freebsd-gnats-submit at freebsd.org
Cc: ixew at hotmail.com
Subject: Re: threads/75273: FBSD 5.3 libpthread (KSE) bug
Date: Wed, 22 Dec 2004 01:05:04 -0500
Here is the non-MIME mangled version of the demo source.
It works for me on -CURRENT.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#define ASSRET(cond) do { \
if (!(cond)) { \
fprintf(stderr, "ASSRET ERROR @ %d -> %s\n", __LINE__, \
strerror(ret == -1 ? errno : ret)); \
exit(EXIT_FAILURE); \
} \
} while (0)
int tock;
void tick()
{
tock = 1;
}
void *pulse(void *arg)
{
int ret;
struct itimerval it;
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
ret = sigprocmask(SIG_BLOCK, &set, NULL);
ASSRET(ret == 0);
sigemptyset(&set);
it.it_interval.tv_sec = 1;
it.it_interval.tv_usec = 0;
it.it_value.tv_sec = 1;
it.it_value.tv_usec = 0;
ret = setitimer(ITIMER_REAL, &it, NULL);
ASSRET(ret == 0);
while (1) {
while (!tock)
sigsuspend(&set);
tock = 0;
putchar('*');
fflush(stdout);
}
}
int main()
{
int ret;
pthread_attr_t attr;
pthread_t thread;
ret = pthread_attr_init(&attr);
ASSRET(ret == 0);
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
ASSRET(ret == 0);
signal(SIGALRM, tick);
ret = pthread_create(&thread, NULL, pulse, NULL);
ASSRET(ret == 0);
printf("Press Enter to cancel the pulse() thread\n");
while (getchar() != '\n');
ret = pthread_cancel(thread);
ASSRET(ret == 0);
ret = pthread_join(thread, NULL);
ASSRET(ret == 0);
printf("Press Enter to end\n");
while (getchar() != '\n');
return 0;
}
More information about the freebsd-threads
mailing list