Hi, all,

isAlive() seems to behave differently on Linux and on Solaris:

Here is a sample program:

import java.lang.*;
  
class MyThread extends Thread {
 
  public void run() {
 
    System.out.println( "Thread " + getName() +
                        ": isAlive() = " + isAlive() );
 
  }
 
  public static void main(String[] args) {
 
    System.out.println( "Thread " + Thread.currentThread().getName() +
                        ": isAlive() = " + Thread.currentThread().isAlive() );
 
    new MyThread().start();
  }
}


Run on Linux, the preceding sample produces:

Thread main: isAlive() = true
Thread Thread-0: isAlive() = true

But, run on Solaris, it says:

Thread + main: IsAlive() = false
Thread + Thread-0: IsAlive() = false


I have quicky modified isAlive() as follow in lib/libnative/java.lang/thread.c,
just to see what was wrong:

static jboolean
isAlive(JNIEnv *env, jobject obj)
{
  JThreadInfo *info = NSA_GetNativeState(obj);
  jboolean ret = (NULL != info && STATE_FINISHED != STATE(info));

  printf( "isAlive: info = %p, state = %d, return = %s\n",
    info, info ? STATE(info) : -1, ret ? "JNI_TRUE" : "JNI_FALSE" );

  return ret;
}

Surprisingly, I got:

isAlive: info = 4aec8, state = 0, return = JNI_TRUE
Thread main: isAlive() = false
isAlive: info = 0, state = -1, return = JNI_FALSE
isAlive: info = 220b50, state = 0, return = JNI_TRUE
Thread Thread-0: isAlive() = false

The second call to isAlive() is performed at the beginning of 
Java_java_lang_Thread_start(). As JThreadInfo is not yet allocated
at this point, the result is correct.

The first and third calls to isAlive() are truly due to
Java_java_lang_Thread_isAlive(). They both return true, but
on the java side, the result (at least on Solaris) is false.

Any idea ?

Thanks for your attention.

--Christophe

Reply via email to