classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Request for change to vm/reference/java/lang/Thread.java


From: Stephen Crawley
Subject: Request for change to vm/reference/java/lang/Thread.java
Date: Wed, 11 Sep 2002 23:16:26 +1000

Hi,

I've recently made a bunch of changes to Kissme to implement methods
in the Thread API.  Part of the process was to switch to using the
GNU Classpath implementation of Threads.java.

However, a problem arises in the way that Kissme creates the first
Thread object.  Basically, we want to just use a regular constructor 
on the Thread class.  The problem is that 4 argument constructor that 
all the others chain to assumes that it can find the current Thread
and copy its priority, thread group and daemon flag.  However, when
we're creating the first Thread, currentThread() returns null, and
a NullPointerException follows quickly.

To get this to work in Kissme, I made some changes to the constructor
that explicitly deal with the case where currentThread returns null,
and sets the priority, thread group and daemon flag appropriately.

The changes are below.  Could they be back-fitted to the Classpath
reference implementation of Thread.java please?

-- Steve

diff -p ../classpath/vm/reference/java/lang/Thread.java 
classes/java/lang/Thread.java
*** ../classpath/vm/reference/java/lang/Thread.java     Wed Sep 11 21:37:30 2002
--- classes/java/lang/Thread.java       Wed Sep 11 22:52:11 2002
*************** public class Thread implements Runnable
*** 252,263 ****
    {
      // Bypass System.getSecurityManager, for bootstrap efficiency.
      SecurityManager sm = Runtime.securityManager;
      if (group == null)
        {
          if (sm != null)
            group = sm.getThreadGroup();
!         if (group == null)
!           group = currentThread().group;
        }
      else if (sm != null)
        sm.checkAccess(group);
--- 252,269 ----
    {
      // Bypass System.getSecurityManager, for bootstrap efficiency.
      SecurityManager sm = Runtime.securityManager;
+     Thread current = currentThread();
      if (group == null)
        {
          if (sm != null)
            group = sm.getThreadGroup();
!         if (group == null)
!         {
!           if (current == null)
!             group = ThreadGroup.root;
!           else
!             group = current.group;
!         }
        }
      else if (sm != null)
        sm.checkAccess(group);
*************** public class Thread implements Runnable
*** 266,274 ****
      // Use toString hack to detect null.
      this.name = name.toString();
      this.toRun = toRun;
!     Thread current = currentThread();
!     priority = current.priority;
!     daemon = current.daemon;
      nativeInit(size);

      group.addThread(this);
--- 272,287 ----
      // Use toString hack to detect null.
      this.name = name.toString();
      this.toRun = toRun;
!     if (current == null)
!       {
!       priority = NORM_PRIORITY;
!       daemon = false;
!       }
!     else
!       {
!       priority = current.priority;
!       daemon = current.daemon;
!       }
      nativeInit(size);

      group.addThread(this);






reply via email to

[Prev in Thread] Current Thread [Next in Thread]