[prev in list] [next in list] [prev in thread] [next in thread] 

List:       omniorb-list
Subject:    RE: [omniORB] Lockup on Solaris 2.5.1 with Y2K patch
From:       David Riddoch <djr () uk ! research ! att ! com>
Date:       1999-06-23 16:30:47
[Download RAW message or body]


Hi,


Lots of valid points have been made, but the following (which addresses
all of them I think) also locks up ...


#include <pthread.h>
#include <iostream.h>
#include <time.h>

pthread_cond_t  cond;
pthread_mutex_t mutex;
pthread_t       thr;
int             died = 0;

extern "C"
void*
worker(void* ptr)
{
  while (1) {
    pthread_mutex_lock(&mutex);
    if( died )  break;
    pthread_mutex_unlock(&mutex);
    struct timespec abs;
    clock_gettime(CLOCK_REALTIME,&abs);
    abs.tv_sec += 1;
    pthread_mutex_lock(&mutex);
    pthread_cond_timedwait(&cond,&mutex,&abs);
    pthread_mutex_unlock(&mutex);
  }
  cerr << "worker exit" << endl;
  pthread_exit(0);
  return 0;
}

int
main(int,char**)
{
  pthread_cond_init(&cond,0);
  pthread_mutex_init(&mutex,0);

  pthread_attr_t attr;

  pthread_attr_init(&attr);

  pthread_create(&thr,&attr,worker,0);

  {
    void** status = 0;
    pthread_mutex_lock(&mutex);
    died = 1;
    pthread_mutex_unlock(&mutex);
    pthread_join(thr,status);
    cerr << "killer done." << endl;
  }

  return 0;
}

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic