This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: PR libgcj/22211


I'm checking this in on the trunk.

This fixes PR libgcj/22211.  The bug was that we would try to
interrupt a thread even if it was not running.  This caused an abort.

The fix is to ensure that access to alive_flag is synchronized, and
then not call _Jv_ThreadInterrupt when the thread is not alive.

Test case included.

Tom

Index: ChangeLog
from  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.

Index: java/lang/Thread.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Thread.java,v
retrieving revision 1.35
diff -u -r1.35 Thread.java
--- java/lang/Thread.java 13 Jan 2005 20:26:38 -0000 1.35
+++ java/lang/Thread.java 29 Jun 2005 17:25:31 -0000
@@ -550,7 +550,7 @@
    *
    * @return whether this Thread is alive
    */
-  public final boolean isAlive()
+  public final synchronized boolean isAlive()
   {
     return alive_flag;
   }
Index: java/lang/natThread.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natThread.cc,v
retrieving revision 1.30
diff -u -r1.30 natThread.cc
--- java/lang/natThread.cc 14 Jan 2005 07:36:27 -0000 1.30
+++ java/lang/natThread.cc 29 Jun 2005 17:25:31 -0000
@@ -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 @@
 {
   checkAccess ();
   natThread *nt = (natThread *) data;
-  _Jv_ThreadInterrupt (nt->thread);
+  JvSynchronize sync (this);
+  if (alive_flag)
+    _Jv_ThreadInterrupt (nt->thread);
 }
 
 void
@@ -215,7 +217,12 @@
   
   // 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 @@
 jint
 _Jv_AttachCurrentThread(java::lang::Thread* thread)
 {
+  JvSynchronize sync (thread);
   if (thread == NULL || thread->startable_flag == false)
     return -1;
   thread->startable_flag = false;
Index: testsuite/libjava.lang/pr22211.java
===================================================================
RCS file: testsuite/libjava.lang/pr22211.java
diff -N testsuite/libjava.lang/pr22211.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.lang/pr22211.java 29 Jun 2005 17:25:32 -0000
@@ -0,0 +1,8 @@
+public class pr22211
+{
+  public static void main(String[] args)
+  {
+    Thread x = new Thread();
+    x.interrupt();
+  }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]