harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Salikh Zakirov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-3253) [drlvm][thread manager] Thread.join() does not ensure the TERMINATED state of a thread
Date Tue, 06 Mar 2007 10:00:24 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-3253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478332
] 

Salikh Zakirov commented on HARMONY-3253:
-----------------------------------------

I think the more correct way would be to make sure that the
VMThreadManager.getState() is called while holding the thread lock, like this way

public Thread.State getState() {
    synchronized (lock) {
        if  (!alive)
            return started ? State.TERMINATED : State.NEW;
        int state = VMThreadManager.getState(this);
    }
    ...

This way, we have two benefits:

1) the code is easier to judge about, because holding thread lock guarantees
that thread is not changing its alive status while we are calling into
VMThreadManager

2) in this way it is compatible with the explicit thread block lifecycle
(HARMONY-3289)

BTW, the State.NEW also deserves special treatment, as it is not necessary
to call into native code to detect that. While it would not be incorrect,
because native structure is allocated at the same time as java.lang.Thread
object, I think decreasing coupling of java code with native is good where
possible.

> [drlvm][thread manager] Thread.join() does not ensure the TERMINATED state of a thread
> --------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3253
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3253
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Elena Semukhina
>         Assigned To: weldon washburn
>         Attachments: accurate-terminated-state.patch
>
>
>  The kernel test ThreadTest.testInterruptTerminated() fails intermittently with the message
"interrupt status has not changed to true" when interrupting a terminated thread. This could
happen when a thread exited join() but its state at that moment was not TERMINATED.
> The following test shows up that the state of a thread after termination is not always
TERMINATED.
> public class TestGetStateJoined {
>     public static void main(String args[]) {
>         int count = 100;
>         for (int i = 0; i < count; i++) {
>             Thread t = new Thread();
>             t.start();
>             try {
>                 t.join();
>             } catch (InterruptedException e) {
>             }
>             Thread.State ts = t.getState();
>             System.out.println("state : " + ts);
>         }
>     }
> }
> The test alternately prints "RUNNABLE" and "TERMINATED" on DRLVM:
> > $DRLVM -showversion TestGetStateJoined
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or
its licensors, as applicable.
> java version "1.5.0" 
> pre-alpha : not complete or compatible
> svn = r512139, (Feb 27 2007), Linux/ia32/gcc 3.3.3, debug build
> http://incubator.apache.org/harmony
> state : TERMINATED
> state : RUNNABLE
> state : TERMINATED
> state : TERMINATED
> state : TERMINATED
> state : RUNNABLE
> state : TERMINATED
> ...
> while on RI it always prints "TERMINATED":
> > $RI -showversion TestGetStateJoined
> java version "1.5.0_08"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
> Java HotSpot(TM) Server VM (build 1.5.0_08-b03, mixed mode)
>  
> state : TERMINATED
> state : TERMINATED
> state : TERMINATED
> ....

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message