harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Salikh Zakirov <Salikh.Zaki...@Intel.com>
Subject Re: [drlvm][threading] a question about JIRA H3253
Date Tue, 06 Mar 2007 09:35:01 GMT
Weldon Washburn wrote:
> Peter,
> I modified your patch to put the variables inside the critical section. 
 >
> public Thread.State getState() {
>     boolean dead = false;
>     synchronized(lock) {
>         if(started && !isAlive()) 
>             dead = true;
>     }
> 
> if (dead) return State.TERMINATED;
> 
> int state = (VMThreadManager.getState(this));

Weldon,

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.

-- 
Salikh Zakirov


Mime
View raw message