To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 19175
19174  |  19176
Subject: 
Re: events or infinite loops... which is better?
Newsgroups: 
lugnet.robotics
Date: 
Sat, 12 Oct 2002 04:50:51 GMT
Viewed: 
1020 times
  
In article <H3u6HL.694@lugnet.com>,
"Rob Stehlik" <Robbby31@hotmail.com> wrote:

So, are these two methods essentially equivalent? I realize you can 'do
something else' with the first method by having your infinite loop in one
task, and work on something else in another task. But, you are really just
jumping between tasks quickly. If events are actually interrupts, then I
think it would be more efficient this way, since the cpu can spend its time
doing other things, and only pauses when the interrupt line is triggered.
Can anyone more knowledgable offer some feedback on this?
Rob

Events are generally going to be more efficient since no bytecodes need
to be executed to continually check for a condition.  However,
efficiency is not always the most important factor.  I don't think
either one is necessarily "better".  A lot depends on what you are
trying to do.  Let's say you want to repeatedly do activity A while
waiting for condition B and then execute C in response.

Using conditions...

while(!B)
{
  A();
}
C();

A() will always run to completion.  This can be convenient if A() has
several steps to it and you want all step to be completed.


Using events...

monitor(B)
{
  while(true) {
    A();
  }
}
C();

A() can be interrupted half way through.  This can be convenient if A()
is going to take a while and you want to respond to B very quickly.

I use both mechanisms in my own programming.

Dave



Message is in Reply To:
  events or infinite loops... which is better?
 
Hi Everyone, I just recently learned how to use event monitoring, and I really like it. My question is whether or not this method is more efficient than infinite loops. I always used to check for sensor readings using an infinite loop something like (...) (22 years ago, 11-Oct-02, to lugnet.robotics)

8 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Contact Recovery Nerd for Speedy USDT / BTC Recovery
8 hours ago
 
Different Sensors Available...
22 hours ago
Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR