Subject:
|
Re: Clarification of access control
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 16 Nov 2000 21:02:09 GMT
|
Viewed:
|
628 times
|
| |
| |
If a task loses its resources (due to an equal or higher priority task
acquiring them), then control leaves the body of the acquire statement. If
there is a "catch" block following the acquire, then the catch block is
executed, otherwise control falls through to the statement following the
acquire. The same flow happens if a task tries to acquire a resource that
is already acquired by a higher priority task.
One way to think of this is that losing resources is a C++/Java style
exception, and an acquire statement implicitly has a catch with no action...
acquire(X)
{
...body...
}
is sort of like
try
{
grabResource(X);
...body...
}
catch (ResourceLostExcetion e)
{
}
and
acquire(X)
{
...body...
}
catch
{
...handler...
}
is like
try
{
grabResource(X);
...body...
}
catch(ResourceLostException e)
{
...handler...
}
So in the example below, whenever the main task choses to acquire the
resource, control will leave the "until(EYE < threshold)" and continue with
the outer while loop...continually trying to acquire the resource unti the
main task releases it, at which point it can try to seek the light again.
Dave
p.s. If you were really coding in C++, you probably wouldn't use
catch-by-value (its evil)...catch-by-pointer or catch-by-reference is
generally better.
p.p.s Thanks for buying the book - I hope you find it informative -aside
from the part where I obviously didn't explain resource access well enough :)
In lugnet.robotics, "Bill Weiss" <bweiss@asset-intertech.com> writes:
> I'm curently reading Extreme Mindstorms. In listing 4.2 (see below) the
> seek task acquires the user defined resource and then enters an inner
> infinite loop looking for a target. It appears to me that if the seek task
> losing ownership of the user defined resource (because the main task has
> requested ownership and it has higher priority) that is will continue
> looking for the target regardless of whether is has ownership of the
> resource or not. I'm I missing something?
> What happens if a task loses ownership of a resource while its in the middle
> of doing some work? Does the task continue, stop, start over?
>
> task seek()
> {
> SetPriority(2);
>
> while(true)
> {
> acquire(ACQUIRE_USER_1) <--- Will only do this once
> {
> Wait(SEEK_DELAY);
> while(true)
> {
> until(EYE < threshold); <---- Will always be looking for
> the target
> find_target();
> }
> }
> }
> }
>
> Bill Weiss
> Senior Software Developer
> ASSET InterTech, Inc.
> bweiss@asset-intertech.com
|
|
Message has 1 Reply: | | Re: Clarification of access control
|
| (...) I forgot to show that resources get released, the functionality is more like this: try { grabResource(X); ...body... releaseResource(X); } catch (ResourceLostException e) { } Dave (24 years ago, 17-Nov-00, to lugnet.robotics)
|
Message is in Reply To:
| | Clarification of access control
|
| I'm curently reading Extreme Mindstorms. In listing 4.2 (see below) the seek task acquires the user defined resource and then enters an inner infinite loop looking for a target. It appears to me that if the seek task losing ownership of the user (...) (24 years ago, 16-Nov-00, to lugnet.robotics)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|