Subject:
|
Re: RCX Programming Questions and Sensor Ideas
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Wed, 11 Nov 1998 19:08:57 GMT
|
Viewed:
|
3264 times
|
| |
| |
lego-robotics@crynwr.com (Paul Haas) writes:
> On Wed, 11 Nov 1998, Todd Lehman wrote:
> > p.s. I also wonder -- in avoiding harmonic task oscillation, is sleeping
> > Might it be sufficient instead simply to busy-count to some random value?
>
> It doesn't have to be random, just each task needs a different delay.
> This is easy, since each task has to run its own version of the code. For
> task 3 insert 3 noops, for task 6, 6 noops, etc...
Does that support an arbitrary number of tasks?
If there are n tasks numbered 1 to n, and task k delays for k cycles on
failure, I think you still have to be careful to make sure that the number
of tasks n is smaller than the loop overhead h in cycles, or else a
low-numbered task will permanently starve a high-numbered task.
That is, if the loop overhead on failure is h cycles, and d[k] is the delay
for task k, you have to make sure that there exists no pair (k1,k2) such
that h+d[k1] = 0 (mod h+d[k2])
An example: Say h is 8 cycles and you have a dozen or so tasks competing for
the same resource. Task 1 would have a total loop time of 8+1=9 cycles and
task 10 would have a total loop time of 8+10=18 cycles. Because task 1's
orbit is exactly 1/2 the running time of task 10's orbit, tasks 1 and 10
are forever in sync and you have a deadlock condition if threads get equal
time slices.
Either there is a safety limit on the number of tasks, or the function d[k]
needs to be something more complex than d[k] = k. Defining d[k] = p[k] - h,
where p[k] is the kth prime number, would be safe.
If there is a proactive yield operation, maybe that would be a good thing to
do right before micro-sleeping.
--ToddL
> The opcode for noop is 0x00. I'm not sure if that is defined in the .nqh
> file. If not, it is easy to add (thanks Dave).
>
> So, let's review; 1) Semaphores are possible. 2) It takes me a few tries
> to write code that works.
>
> Anyone want to write an example program that uses semaphores? We could
> put a link to that code in the FAQ or give it to Dave Baum to put in with
> the other nqc examples.
>
> --
> paulh@hamjudo.com http://www.hamjudo.com
> The April 97 WebSight magazine describes me as "(presumably) normal".
|
|
Message is in Reply To:
| | Re: RCX Programming Questions and Sensor Ideas
|
| (...) I think "oops" applies in this case. Your fix looks correct. (...) It doesn't have to be random, just each task needs a different delay. This is easy, since each task has to run its own version of the code. For task 3 insert 3 noops, for task (...) (26 years ago, 11-Nov-98, to lugnet.robotics)
|
17 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|