Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Sep 2002 23:17:38 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Giorgos Keramidas <keramida@ceid.upatras.gr>, Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.ORG
Subject:   Re: Process/thread states.
Message-ID:  <Pine.BSF.4.21.0209042235470.34499-100000@InterJet.elischer.org>
In-Reply-To: <3D76E737.B46FDA1E@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On Wed, 4 Sep 2002, Terry Lambert wrote:

> Giorgos Keramidas wrote:
> > if ((td->td_wchan == 0) && (td->td_state & TDS_RUNNING ||
> >     td->td_state & TDS_SUSPENDED))
> > 
> > It's not bad to know what is going on `within' the td struct, imho.
> 
> 
> 
> if ((td->td_wchan == 0) && (td->td_state & (TDS_RUNNING|TDS_SUSPENDED)))
> 
> 
> is more natural.

you can not test TDS_RUNNING|TDS_SUSPENDED as they are two 
states that are mutually exclusive.

either the state is one or the other.. they are NOT bits....

however:

the state of being on the sleep queue can occur in parallel with the other
states, e.g. on the run queue, or running or on the suspend queue.
Sleeping is really only being on the sleep queue without any other
state taking precedence.
This means that to truely represent the queue and run states of a thread
the state variable consists of a state field with several values
and a separate bit that represents the background reality of it also being
on the sleep queue, and thus able to be awoken. There are also 
possibilities that a thread having been swapped out (as part of a process)
that must also be kept orthogonal to whether the thread is suspended or
sleeping or runnable. if this really does turn out to be the case
REAL thread state tracking requires 3 orthognal tests. For this reason I
want touse a macro to allow,
1/ experimentation on how thisis best done
2/ hiding of the sometime messy tests with meaningful named abstractions.


> 
> Neither one of these works properly if there is more than
> one bit hidden in either of these; you have to get a lot more
> complicated:
> 

this one could be real:
 if ((td->td_wchan == 0) && (td->td_state & TD_ST_MASK == TDS_UNQUEUED) &&
      ((td->td_state & TDS_SWAPPED) == 0))
	setrunnable(td);

I'd rather make it

if (td_on_sleepq_only(td) && !td_is_swapped(td))
	setrunnable(td);

Isn't that somewhat easier to understand?

> 
> That *still* doesn't work if, say, TDS_XXX is a superset of the
> bits in TDS_SUSPENDED.


> 
> I personally dislike the idea of combined bits, without explicit
> equality tests.

I have no idea what you mean by that.

> 
> The problem that's trying to be solved here is the one of how
> do you represent a combinatorial state in a single comparison,
> and the equivalency of one combinatorial state and another for
> the purposes of whether or not some code should be run (as in
> this specific case).
> 
> The reality is probably that this state should be explicitly
> multiplied out in the code, so that it becomes a single value
> compare.

sometimes you want otherwise.. e.g. 
What is the base state REGARDLESS of whether it is on the sleep queue.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0209042235470.34499-100000>