tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Lars Rossen <Lars.Rossen () netman ! dk>
To: tru64-unix-managers
Subject: Possible bug in pthreads library.
Date: Fri, 02 Jun 1995 11:31:15 +0000	[thread overview]
Message-ID: <96075320706388.tru64-unix-managers.marc@archive.invalid> (raw)


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

                 reply	other threads:[~1995-06-02 11:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

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