Index: trunk/include/sh_pthread.h
===================================================================
--- trunk/include/sh_pthread.h	(revision 319)
+++ trunk/include/sh_pthread.h	(revision 320)
@@ -23,11 +23,20 @@
 	do {                                                               \
                 int oldtype;                                               \
+		int executeStack = 1;                                      \
 		pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);  \
                 pthread_cleanup_push(sh_pthread_mutex_unlock, (void*)&(M));\
                 pthread_mutex_lock(&(M))
 
+#define SH_MUTEX_TRYLOCK(M)						   \
+	do {                                                               \
+                int oldtype;                                               \
+		int executeStack = 0;                                      \
+		pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);  \
+                pthread_cleanup_push(sh_pthread_mutex_unlock, (void*)&(M));\
+                pthread_mutex_trylock(&(M));                               \
+		executeStack = 1
 
 #define SH_MUTEX_UNLOCK(M)						   \
-		pthread_cleanup_pop(1);                                    \
+		pthread_cleanup_pop(executeStack);                         \
                 pthread_setcanceltype(oldtype, NULL);                      \
 	} while (0)
@@ -147,4 +156,5 @@
 #define SH_MUTEX_EXTERN(M)			extern void *SH_MUTEX_DUMMY_ ## M
 #define SH_MUTEX_LOCK(M)			((void)0)
+#define SH_MUTEX_TRYLOCK(M)			((void)0)
 #define SH_MUTEX_UNLOCK(M)			((void)0)
 #define SH_MUTEX_LOCK_UNSAFE(M)			((void)0)
Index: trunk/src/sh_hash.c
===================================================================
--- trunk/src/sh_hash.c	(revision 319)
+++ trunk/src/sh_hash.c	(revision 320)
@@ -1554,5 +1554,8 @@
 
   SL_ENTER(_("sh_hash_hashdelete"));
-  SH_MUTEX_LOCK(mutex_hash);
+
+  /* need deadlock detection here if called from exit handler 
+   */
+  SH_MUTEX_TRYLOCK(mutex_hash);
 
   if (IsInit == 0) 
@@ -1570,4 +1573,5 @@
   ; /* 'label at end of compound statement */
   SH_MUTEX_UNLOCK(mutex_hash);
+
   SL_RET0(_("sh_hash_hashdelete"));
 }
