Subject:
|
Re: LeJos threads / sleep() takes too long
|
Newsgroups:
|
lugnet.robotics.rcx.java
|
Date:
|
Mon, 1 Apr 2002 18:34:34 GMT
|
Viewed:
|
3848 times
|
| |
| |
The priority mechanism used in lejos is the same as that specified in the
Real Time Specification for Java (RTSJ): Threads of a higher priority will
absolutely block threads of a lower priority as long as they remain runnable.
The sensor listener thread runs at MAX_PRIORITY as it is important for
sensor events to be handled in a timely fashion.
So you have three possible solutions, starting with the way that I would do it:
1) An application should not perform any serious handling of the sensor
event in sensor listeneing thread. It should instead hand the work off to a
lower priority thread to do the work. It is up to you to determine what
priority that thread should be. The easiest way to do this is for the work
thread to call wait() on some object and for the event handler to call
notify() on that same object - this will wake the waiting() thread up.
In addition, if you want your sleep() call to run in a timely fashion too,
you should create a thread, set its priority to MAX_PRIORITY and have it do
the sleep for you (threads of the same priority are timesliced).
2) In main, set the current thread's priority to MAX_PRIORITY. All threads
from then on will run at the same priority and will be timesliced effectively.
3) Don't use sensor listeners. Just read the sensor values yourself whenever
you want to. This could get tricky as some of the standard classes (e.g.
ProximitySensor) use sensor listeners internally.
> In lugnet.robotics.rcx.java, Juergen Stuber writes:
>
> Hi Bart,
>
> Bart Pattyn <rcx@ranavision.com> writes:
> >
> > I have the impression my "try { sleep(nnn) }" takes
> > a somewhat arbitrary time. It's 'at least' nnn milisec,
> > but often much longer (particularly when sensorthread
> > has a lot of work, it seems).
>
> if you mean LISTENER_THREAD then that sounds plausible.
>
> > Is this 'standard' Java behaviour?
>
> Yes, LISTENER_THREAD has maximum priority, so it runs before
> any threads of lower priority, even yield doesn't help.
>
> > It becomes very difficult to have a timed 'small
> > turn left' routine. Sometimes it turns a bit (as I want),
> > sometimes it makes a 180°. And no, I can't miss a rotation
> > sensor on this one (already 'overloading' sensors with light+touch etc)
>
> Yes, I think we'll have to fix that somehow.
>
> > It seems a bit akward to go about and "implement" a
> > low-level sleep?! ( slicing sleep into 10ms and verify
> > system clock?)
>
> That won't help you, if your thread doesn't run.
>
> > Is thread-priority the problem here? (not clear if
> > higest-priority threads really 'yields()')
>
> I think the problem is that the sensor thread has maximum priority
> and too much work to do, so it blocks other threads.
>
> > Any suggestions?
>
> Play with Poll.setThrottle.
>
> Have fun
>
> Jürgen
|
|
Message is in Reply To:
| | Re: LeJos threads / sleep() takes too long
|
| Hi Bart, (...) if you mean LISTENER_THREAD then that sounds plausible. (...) Yes, LISTENER_THREAD has maximum priority, so it runs before any threads of lower priority, even yield doesn't help. (...) Yes, I think we'll have to fix that somehow. (...) (23 years ago, 6-Mar-02, to lugnet.robotics.rcx.java)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|