Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Threading issues on RH9



I have been having problems with getting vdr-1.1.33 to work reliably on a RH9 with a standard RH kernel (2.4.20-9).

The problem with VDR seems to stem from the fact that the RH kernel includes the new NPTL "Native Posix Thread Library". This has changed a few things which breaks the VDR threading.

The main problem is that getpid() returns the same PID for all threads. There are a number of places in the VDR code which assume getpid() returns a unique number for each thread.

There are a number of different ways around this issue:
- Don't use a RH supplied kernel
- Set the environment variable "LD_ASSUME_KERNEL=2.4.1" before running VDR, this forces the threading model back to the older behaviour.
- Fix the issues in the VDR code. I have attached a patch which fixes some of the getpid() issues.

There is still one big remaining issue which I haven't solved, this is how to deal with the thread code which tries to see if another thread is still running using kill(). This is broken in the new thread model because all the threads appear to have the same PID. Perhaps pthread_getattr_np() could be used but it seems GNU specific and I can't find any docs on what it returns.

Jon
--- old/thread.c	2003-05-18 13:45:13.000000000 +0100
+++ thread.c	2003-05-30 22:45:04.000000000 +0100
@@ -30,7 +30,7 @@
 
 void cCondVar::Wait(cMutex &Mutex)
 {
-  if (Mutex.locked && Mutex.lockingPid == getpid()) {
+  if (Mutex.locked && pthread_equal( Mutex.lockingTid,  pthread_self())) {
      int locked = Mutex.locked;
      Mutex.locked = 0; // have to clear the locked count here, as pthread_cond_wait
                        // does an implizit unlock of the mutex
@@ -43,7 +43,7 @@
 {
   bool r = true; // true = condition signaled false = timeout
 
-  if (Mutex.locked && Mutex.lockingPid == getpid()) {
+  if (Mutex.locked && pthread_equal( Mutex.lockingTid, pthread_self())) {
      struct timeval now;                   // unfortunately timedwait needs the absolute time, not the delta :-(
      if (gettimeofday(&now, NULL) == 0) {  // get current time
         now.tv_usec += TimeoutMs * 1000;   // add the timeout
@@ -61,7 +61,7 @@
         if (pthread_cond_timedwait(&cond, &Mutex.mutex, &abstime) == ETIMEDOUT)
            r = false;
         Mutex.locked = locked;
-        Mutex.lockingPid = getpid();
+        Mutex.lockingTid = pthread_self();
         }
      }
   return r;
@@ -83,7 +83,7 @@
 
 cMutex::cMutex(void)
 {
-  lockingPid = 0;
+  lockingTid = 0;
   locked = 0;
   pthread_mutex_init(&mutex, NULL);
 }
@@ -95,9 +95,9 @@
 
 void cMutex::Lock(void)
 {
-  if (getpid() != lockingPid || !locked) {
+  if ( !pthread_equal(pthread_self(), lockingTid) || !locked) {
      pthread_mutex_lock(&mutex);
-     lockingPid = getpid();
+     lockingTid = pthread_self();
      }
   locked++;
 }
@@ -105,7 +105,7 @@
 void cMutex::Unlock(void)
 {
  if (!--locked) {
-    lockingPid = 0;
+    lockingTid = 0;
     pthread_mutex_unlock(&mutex);
     }
 }
--- old/thread.h	2003-05-03 15:03:36.000000000 +0100
+++ thread.h	2003-05-30 22:02:51.000000000 +0100
@@ -32,7 +32,7 @@
   friend class cCondVar;
 private:
   pthread_mutex_t mutex;
-  pid_t lockingPid;
+  pthread_t lockingTid;
   int locked;
 public:
   cMutex(void);

Home | Main Index | Thread Index