re PR libgcj/22211 ([4.0 only] Thread.interrupt sometimes causes abort if thread...
authorTom Tromey <tromey@redhat.com>
Wed, 29 Jun 2005 17:36:16 +0000 (17:36 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 29 Jun 2005 17:36:16 +0000 (17:36 +0000)
PR libgcj/22211:
* testsuite/libjava.lang/pr22211.java: New file.
* java/lang/natThread.cc (finish_): Synchronize when updating
alive_flag.
(_Jv_AttachCurrentThread): Likewise.
(interrupt): Only call _Jv_ThreadInterrupt if thread is alive.
* java/lang/Thread.java (isAlive): Now synchronized.

From-SVN: r101430

libjava/ChangeLog
libjava/java/lang/Thread.java
libjava/java/lang/natThread.cc
libjava/testsuite/libjava.lang/pr22211.java [new file with mode: 0644]

index 356b3ba0ab7793e52b1e9fd28f028e27d20d29bd..ba83c06cf2e6488cee6903030838da6a5d91b541 100644 (file)
@@ -1,3 +1,13 @@
+2005-06-29  Tom Tromey  <tromey@redhat.com>
+
+       PR libgcj/22211:
+       * testsuite/libjava.lang/pr22211.java: New file.
+       * java/lang/natThread.cc (finish_): Synchronize when updating
+       alive_flag.
+       (_Jv_AttachCurrentThread): Likewise.
+       (interrupt): Only call _Jv_ThreadInterrupt if thread is alive.
+       * java/lang/Thread.java (isAlive): Now synchronized.
+
 2005-06-29  Tom Tromey  <tromey@redhat.com>
 
        * interpret.cc (run) <insn_checkcast, checkcast_resolved>: Use
index ef4a3f472f0f92a84a5c12d05277c92e8ccdd1e1..b58ff175c0239e850e81946062ea84509e688054 100644 (file)
@@ -550,7 +550,7 @@ public class Thread implements Runnable
    *
    * @return whether this Thread is alive
    */
-  public final boolean isAlive()
+  public final synchronized boolean isAlive()
   {
     return alive_flag;
   }
index e79ab11b9c600a07ec5b9c53a7cdfcdf483dabd1..f1064f17c690cab3f50b780e7e5b7b569c16699d 100644 (file)
@@ -1,6 +1,6 @@
 // natThread.cc - Native part of Thread class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -115,7 +115,9 @@ java::lang::Thread::interrupt (void)
 {
   checkAccess ();
   natThread *nt = (natThread *) data;
-  _Jv_ThreadInterrupt (nt->thread);
+  JvSynchronize sync (this);
+  if (alive_flag)
+    _Jv_ThreadInterrupt (nt->thread);
 }
 
 void
@@ -215,7 +217,12 @@ java::lang::Thread::finish_ ()
   
   // Signal any threads that are waiting to join() us.
   _Jv_MutexLock (&nt->join_mutex);
-  alive_flag = false;
+
+  {
+    JvSynchronize sync (this);
+    alive_flag = false;
+  }
+
   _Jv_CondNotifyAll (&nt->join_cond, &nt->join_mutex);
   _Jv_MutexUnlock (&nt->join_mutex);  
 }
@@ -392,6 +399,7 @@ _Jv_SetCurrentJNIEnv (JNIEnv *env)
 jint
 _Jv_AttachCurrentThread(java::lang::Thread* thread)
 {
+  JvSynchronize sync (thread);
   if (thread == NULL || thread->startable_flag == false)
     return -1;
   thread->startable_flag = false;
diff --git a/libjava/testsuite/libjava.lang/pr22211.java b/libjava/testsuite/libjava.lang/pr22211.java
new file mode 100644 (file)
index 0000000..87a8e55
--- /dev/null
@@ -0,0 +1,8 @@
+public class pr22211
+{
+  public static void main(String[] args)
+  {
+    Thread x = new Thread();
+    x.interrupt();
+  }
+}