Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Dec 2004 06:10:24 GMT
From:      Craig Rodrigues <rodrigc@crodrigues.org>
To:        freebsd-threads@FreeBSD.org
Subject:   Re: threads/75273: FBSD 5.3 libpthread (KSE) bug
Message-ID:  <200412220610.iBM6AOuo012632@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR threads/75273; it has been noted by GNATS.

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: freebsd-gnats-submit@freebsd.org
Cc: ixew@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;
 }
  



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200412220610.iBM6AOuo012632>