diff --git a/src/threads.c b/src/threads.c
index 0ccd6462aa341205ed2a1258d9e5439c77b4cff8..ce12dfa49c8c6a731665cacd2731da1583f207f8 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: threads.c,v 1.57 1998/02/27 20:09:04 marcus Exp $");
+RCSID("$Id: threads.c,v 1.58 1998/03/01 03:33:50 hubbe Exp $");
 
 int num_threads = 1;
 int threads_disabled = 0;
@@ -168,7 +168,7 @@ void thread_table_init()
 
 unsigned INT32 thread_table_hash(THREAD_T *tid)
 {
-  return hashmem((unsigned char *)tid, sizeof(*tid), 16) % THREAD_TABLE_SIZE;
+  return th_hash(*tid) % THREAD_TABLE_SIZE;
 }
 
 void thread_table_insert(struct object *o)
@@ -198,13 +198,18 @@ struct thread_state *thread_state_for_id(THREAD_T tid)
   unsigned INT32 h = thread_table_hash(&tid);
   struct thread_state *s = NULL;
   mt_lock( & thread_table_lock );
-  if(thread_table_chains[h] == NULL) {
+  if(thread_table_chains[h] == NULL)
+  {
     /* NULL result */
-  } else if((s=thread_table_chains[h])->id == tid) {
+  }
+  else if(th_equal((s=thread_table_chains[h])->id, tid))
+  {
     /* Quick return */
-  } else {
+  }
+  else
+  {
     while((s = s->hashlink) != NULL)
-      if(s->id == tid)
+      if(th_equal(s->id, tid))
 	break;
     if(s != NULL) {
       /* Move the thread_state to the head of the chain, in case
diff --git a/src/threads.h b/src/threads.h
index 35d4830cef8538151e6673131b17324851e2df36..d315955b9ccfe4ebdb8a6e7bbc87eef71dc7239f 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -150,6 +150,8 @@ extern pthread_attr_t small_pattr;
 #define th_exit(X)	exit(X)
 #define th_self()	getpid()
 #define th_yield()	sginap(0)
+#define th_equal(X,Y) ((X)==(Y))
+#define th_hash(X) ((unsigned INT32)(X))
 
 /*
  * No cond_vars yet
@@ -170,6 +172,8 @@ extern pthread_attr_t small_pattr;
 #define th_self() GetCurrentThread()
 #define th_destroy(X)
 #define th_yield() Sleep(0)
+#define th_equal(X,Y) ((X)==(Y))
+#define th_hash(X) ((unsigned INT32)(X))
 
 #define MUTEX_T HANDLE
 #define mt_init(X) CheckValidHandle((*(X)=CreateMutex(NULL, 0, NULL)))
@@ -250,6 +254,14 @@ struct thread_state {
 #define th_yield()
 #endif
 
+#ifndef th_equal
+#define th_equal(X,Y) (!MEMCPY(&(X),&(Y),sizeof(THREAD_T)))
+#endif
+
+#ifndef th_hash
+#define th_hash(X) hashmem(&(X),sizeof(THREAD_T), 16)
+#endif
+
 /* Define to get a debug-trace of some of the threads operations. */
 /* #define VERBOSE_THREADS_DEBUG */