Possible bug in pthreads library.

From: Lars Rossen <Lars.Rossen_at_netman.dk>
Date: Fri, 2 Jun 1995 13:31:15 +0200

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_at_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
Received on Fri Jun 02 1995 - 14:22:08 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:45 NZDT