How can you control which LWP your thread is scheduled in???
What good are thread priorities and pre-emptive thread scheduling
if you cannot dictate which threads run under which LWP?
I've run into an interesting "feature" in Solaris threads. I'm building
MT apps on Solaris 2.4 x86, and from reading Sun's docs on threads, thread
scheduling seemed to be very nice. I especially liked the fact that
scheduling between threads (within the same LWP) is apparently pre-emptive
and deterministic -- the docs repeatedly state that there cannot be a
situtation where a high priority thread is ready to run in the LWP
but isn't.
Using this fact, I schedule two threads to run with a clear priority
between them. Thread 1 (lower priority) utilizes a resource for
about 250ms, and locks a mutex around it. it then frees the mutex,
but almost immediately grabs it again for another 250ms, and so
on for 1 minute... Thread 2 (higher priority) wakes up every 10 seconds,
and wants to briefly use the same resource, attempting to lock it's
associated mutex. At this point, it should have to wait at most 250ms
for the lower priority thread to release the mutex. The mutex release
call should immediately pre-empt the lower priority thread, and switch
to the higher priority thread, giving it the mutex.
In reality, Thread 2 (higher priority) doesn't get the mutex at all
until the lower priority thread completes (after 1 min). It seems to
be racing for the same mutex, but it does not pre-empt the lower
priority thread. Since the pre-emption doesn't happen, the lower
pririty thread holds on to the mutex for 250ms and releases it
for only a few microseconds in each cycle. Under these condictions
the higher priority thread has virtualy no chance of grabbing the mutex
away...
The only explanation I can find for this is that all the nice
pre-emption features are documented to work between threads in
the *same LWP*. Apparently my threads are scheduled to different
LWP's, and since I don't set those to a real-time priority class,
they use the normal "fair" scheduling between them, with no inter-LWP
pre-emption, leaving the "higher priority" thread hung waiting...
Alas, I find no way of forcing two threads to reside in the same
LWP. As long as this cannot be done, inter-thread priority is virtually
meaningless. Since there is no way of telling which LWP a thread will
end up in, there is no way to design for "deterministic" inter-thread
behaviour in an M.T. program (with the exception of assigning each thread
a bound, Real Time class LWP). Needless to say, R.T Class LWPs have
the BIG drawback of* your system frequently if your own thread
code is buggy (a near certainty when under development).
Ideas, suggestions, or explanations, anyone?
AdvThanks,
--
---------------------------------------------------------------------
-- Gil Tene Cloud Seven, Inc. "Some days it just -
-- (415)-254-0910 172 Ada Ave #10 doesn't pay to go to -
---------------------------------------------------------------------