Subject:
|
Re: Which way is faster?
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Fri, 13 Apr 2001 17:41:03 GMT
|
Viewed:
|
2908 times
|
| |
 | |
By "fastest", I assume you mean the smallest worst case latency between
a condition happening and the RCX responding to it.
Option #2 has the drawback that while the RCX is responding to one
condition, it won't be looking for the other ones. So the worst case
latency depends on statements executed when a condition is true. For
that reason, option #1 is a much better alternative if you expect
multiple conditions to become true close to one another and want to
respond to them all concurrently. However, if concurrency is not
desired, then option 2 is good.
A better approach, however, is to use events and put the task to sleep
(by calling Wait()) while waiting for events. If you want concurrency,
then have multiple tasks each waiting for a single event. If you do not
want concurrency, then have one task waiting for multiple events.
Either way, using event monitoring and putting the task(s) to sleep
generally results in the best nominal latency, and worst case shouldn't
be any longer than with the non-event approaches. I think there have
been previous lugnet posts about how to do this with events, a search
like http://news.lugnet.com/robotics/?q=EVENT_MASK should turn up some
information.
Dave Baum
In article <GBqn38.9CF@lugnet.com>, "Zhengrong Zang"
<zhengrong.zang@nokia.com> wrote:
> I want to know which way is faster:
> 1. Use three tasks to watch sensors
> task watch1()
> {
> while (true) {
> if () {
> ..
> }
> }
> }
> task watch2()
> {
> while (true) {
> if () {
> ..
> }
> }
> }
> task watch3()
> {
> while (true) {
> if () {
> ..
> }
> }
> }
>
> 2. Use one task with multi if-else
> task watch()
> {
> while (true) {
> if () {
> ..
> }
> else if () {
> ..
> }
> else if () {
> ..
> }
> }
> }
>
> Zhengrong
--
reply to: dbaum at enteract dot com
|
|
Message is in Reply To:
 | | Which way is faster?
|
| I want to know which way is faster: 1. Use three tasks to watch sensors task watch1() { while (true) { if () { .. } } } task watch2() { while (true) { if () { .. } } } task watch3() { while (true) { if () { .. } } } 2. Use one task with multi (...) (24 years ago, 13-Apr-01, to lugnet.robotics.rcx.nqc)
|
2 Messages in This Thread:   
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|