diff --git a/src/interpret.c b/src/interpret.c
index 2d9fa132df0e928e30650aade1726c85a902de19..097d7d691c9d6427d6ee7d974a7ed0f1d1755dc1 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: interpret.c,v 1.122 1999/05/02 08:11:43 hubbe Exp $");
+RCSID("$Id: interpret.c,v 1.123 1999/05/08 00:33:18 hubbe Exp $");
 #include "interpret.h"
 #include "object.h"
 #include "program.h"
@@ -649,6 +649,17 @@ void mega_apply2(enum apply_type type, INT32 args, void *arg1, void *arg2)
 #endif
 #endif
 
+#if defined(PIKE_DEBUG) && defined(_REENTRANT)
+  if(d_flag)
+    {
+      if( thread_id && !th_equal( OBJ2THREAD(thread_id)->id, th_self()) )
+	fatal("Current thread is wrong.\n");
+	
+      if(thread_for_id(th_self()) != thread_id)
+	fatal("thread_for_id() (or thread_id) failed in mega_apply! %p != %p\n",thread_for_id(th_self()),thread_id);
+      }
+#endif
+
   switch(type)
   {
   case APPLY_STACK:
diff --git a/src/interpreter.h b/src/interpreter.h
index 566d522fd469c3b87b82d2030df2a7f37bc13e13..69cbc29b18cf83047741f60e038d858a44028024 100644
--- a/src/interpreter.h
+++ b/src/interpreter.h
@@ -31,10 +31,15 @@ static int eval_instruction(unsigned char *pc)
 #ifdef PIKE_DEBUG
     if(d_flag)
     {
-#if defined(_REENTRANT) && !defined(__NT__)
+#ifdef _REENTRANT
+#ifndef __NT__
       if(!mt_trylock(& interpreter_lock))
 	fatal("Interpreter running unlocked!\n");
 #endif
+      if(d_flag>1 && thread_for_id(th_self()) != thread_id)
+        fatal("thread_for_id() (or thread_id) failed in interpreter.h! %p != %p\n",thread_for_id(th_self()),thread_id);
+#endif
+
       sp[0].type=99; /* an invalid type */
       sp[1].type=99;
       sp[2].type=99;