Hi,

On Thu, Jan 01, 2009 at 11:46:31AM +0100, Matthias Kilian wrote:
> > pthread_mutex_unlock() is called, evidently from fileLock(), with an
> > invalid mutex.
> > 
> > NetBSD's pthread implementation differs from Linux in its intolerance
> > of such things.  I have found errors where someone forgets that a mutex
> > was never used and tries to unlock it.  I guess you could do that all day
> > long on Linux without noticing anything, but NetBSD aborts the program.
> > In the present case, I don't see anything like that wrong in rts/FileLock.c,
> > though.  I'm stumped.
> > 
> > So I'm checking, has anyone else built 6.10 on NetBSD?

Could you (and anyone else on any operating system using pthreads)
please try to build with the patch below? It checks the return
values of pthread_mutex_lock() and pthread_mutex_unlock() by default
(even if DEBUG isn't defined) and contains some other uncluttering.

Seems to work fine here on OpenBSD (for ghc-head), but before I
send out a darcs patch, I'd like to see some results on other
systems.[1]

Of course, the patch won't fix the problem for NetBSD, but it may
give some more hints.

Ciao,
        Kili

[1] and if you insist in darcs patches, just pull from
http://darcs.volkswurst.de/users/kili/ghc-6.10/ghc/ or
http://darcs.volkswurst.de/users/kili/ghc/

diff -x _darcs -rNup ../ghc/includes/OSThreads.h ./includes/OSThreads.h
--- ../ghc/includes/OSThreads.h Sun Jan  4 22:28:46 2009
+++ ./includes/OSThreads.h      Sun Jan  4 22:11:34 2009
@@ -23,6 +23,7 @@
 #else
 
 #include <pthread.h>
+#include <errno.h>
 
 typedef pthread_cond_t  Condition;
 typedef pthread_mutex_t Mutex;
@@ -34,47 +35,26 @@ typedef pthread_key_t   ThreadLocalKey;
 #define INIT_COND_VAR       PTHREAD_COND_INITIALIZER
 
 #ifdef LOCK_DEBUG
+#define LOCK_DEBUG_BELCH(what, mutex) \
+  debugBelch("%s(0x%p) %s %d\n", what, mutex, __FILE__, __LINE__)
+#else
+#define LOCK_DEBUG_BELCH(what, mutex) /* nothing */
+#endif
 
+/* Always check the result of lock and unlock. */
 #define ACQUIRE_LOCK(mutex) \
-  debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \
-  pthread_mutex_lock(mutex)
-#define RELEASE_LOCK(mutex) \
-  debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \
-  pthread_mutex_unlock(mutex)
-#define ASSERT_LOCK_HELD(mutex) /* nothing */
-
-#elif defined(DEBUG) && defined(linux_HOST_OS)
-#include <errno.h>
-/* 
- * On Linux, we can use extensions to determine whether we already
- * hold a lock or not, which is useful for debugging.
- */
-#define ACQUIRE_LOCK(mutex) \
+  LOCK_DEBUG_BELCH("ACQUIRE_LOCK", mutex); \
   if (pthread_mutex_lock(mutex) == EDEADLK) { \
     barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \
   }
+
 #define RELEASE_LOCK(mutex) \
+  LOCK_DEBUG_BELCH("RELEASE_LOCK", mutex); \
   if (pthread_mutex_unlock(mutex) != 0) { \
     barf("RELEASE_LOCK: I do not own this lock: %s %d", __FILE__,__LINE__); \
   }
 
 #define ASSERT_LOCK_HELD(mutex) ASSERT(pthread_mutex_lock(mutex) == EDEADLK)
-
-#define ASSERT_LOCK_NOTHELD(mutex)             \
-  if (pthread_mutex_lock(mutex) != EDEADLK) {  \
-     pthread_mutex_unlock(mutex);              \
-  } else {                                     \
-    ASSERT(0);                                 \
-  }
-
-
-#else
-
-#define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex)
-#define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex)
-#define ASSERT_LOCK_HELD(mutex) /* nothing */
-
-#endif
 
 #endif // CMINUSMINUS
 
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to