tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* Possible bug in pthreads library.
@ 1995-06-02 11:31 Lars Rossen
  0 siblings, 0 replies; only message in thread
From: Lars Rossen @ 1995-06-02 11:31 UTC (permalink / raw)
  To: tru64-unix-managers


Dear all

The program below shows what we belive is an error in the pthread_cond_timedwait() call.

when called with days < 25 then all is ok.
If called with 24 < days < 49 then the timer times out imediatly (not ok).
If called with days > 50 the timer call fails when compiled and run on
OSF/1 v3.2 and 3.2A but on v2.1 it seem ok (we have not waited 50 days
to verify :-)

Could someone please help.

Cheers
Lars
+-----------------------------------------------------------------------------+
| Lars Rossen                          E-mail: Lars.Rossen@netman.dk          |
| NetMan A/S                           Phone : +45 3966 4020                  |
| Vandtaarnsvej 77                     Fax   : +45 3966 0675                  |
| 2860 Soeborg                         Home  : Phone: +45 3670 3676           |
| Denmark                              Knud Anchersvej 95, 2610 R{\o}dovre    |
+-----------------------------------------------------------------------------+



********************************************************************************
#include <values.h>
#include <stdio.h>
#include <timers.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <errno.h>

pthread_mutex_t mutex;
pthread_cond_t cond;


TimerMain(int days)
{
  struct timespec abstime;

  /* lock mutex before wait */
  pthread_mutex_lock(&mutex);

  while(1)
  {
    struct timespec delta;

    delta.tv_sec = days*24*60*60;
    delta.tv_nsec = 0;

    pthread_get_expiration_np(&delta, &abstime);

    // Wait for timeout
    if ( pthread_cond_timedwait(&cond, &mutex, &abstime) == -1 )
    {
      if ( errno != EAGAIN )
      {
        printf("Bad timer call\n");
        break;
      }
      // Timeout
      printf("Timeout\n");
    }
    // Else signaled 
  }
  pthread_mutex_unlock(&mutex);
  return 0;
}

int
main(int argc, char *argv[])
{

  if ( argc !=2 )
  {
    printf("Usage: %s <days to timeout>\n", argv[0]);
    exit(1);
  }
  pthread_mutex_init(&mutex,pthread_mutexattr_default);
  pthread_cond_init(&cond,pthread_condattr_default);
  TimerMain(atoi(argv[1]));
  return 0;
}

********************************************************************************

Compile it with:

cc prog.c -lpthreads -lm -lmach -lc_r -o prog

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-06-02 11:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-06-02 11:31 Possible bug in pthreads library Lars Rossen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox