comp.lang.ada
 help / color / mirror / Atom feed
* Protected Object: little question
@ 2001-11-30 19:29 Bruno Hergott
  2001-11-30 21:15 ` Dale Stanbrough
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Bruno Hergott @ 2001-11-30 19:29 UTC (permalink / raw)


Hello,

Protected Object is really helpfull to provide read and/or write access to a ressource
in a multitask environnement.
I think i have understand the basis but something remains strange for me.

Before all, it could be better to write there the RM Ch. 9. 5.1 concerning protected
objects:
(1): A protected subprogram is a subprogram declared immediately within a
protected_definition.
Protected procedures provide exclusive read-write access to the data of a protected
object;
protected functions provide concurrent read-only access to the data.
(2): Within the body of a protected function (or a function declared immediately within a
protected_body), the current instance of the enclosing protected unit is defined to be a
constant
(that is, its subcomponents may be read but not updated). Within the body of a protected
procedure (or a procedure declared immediately within a protected_body), and within an
entry_body, the current instance is defined to be a variable (updating is permitted).
(4) A new protected action is not started on a protected object while another protected
action
on the same protected object is underway, unless both actions are the result of a call on
a
protected function. This rule is expressible in terms of the execution resource associated
with
the protected object :
 - (5) Starting a protected action on a protected object corresponds to acquiring the
execution
resource associated with the protected object, either for concurrent read-only access if
the
protected action is for a call on a protected function, or for exclusive read-write access

otherwise;
 - (6) Completing the protected action corresponds to releasing the associated execution
resource.
...

My question is:
If i want to implement an action wich does only read access to the protected data and wich
can
be called by 2 tasks at the same time, i must write a function.
But i may not need the return value of this function. Because what i want is not really a
function.
What i want is "the thing in a protected object to do only read access to the protected
data
and wich can be called by 2 tasks at the same time".
And so i must for example call this action like this:
My_Boolean_Return_Value_I_Dont_Want := My_Protected_Object.MyProtectedFunction(..);
It seems to strange to be true...

Or is there something i haven't understand ?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-11-30 19:29 Protected Object: little question Bruno Hergott
@ 2001-11-30 21:15 ` Dale Stanbrough
  2001-12-01  4:00   ` Mark Lundquist
  2001-11-30 22:37 ` Jeffrey Carter
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Dale Stanbrough @ 2001-11-30 21:15 UTC (permalink / raw)


Bruno Hergott wrote:

> If i want to implement an action wich does only read access to the protected 
> data and wich
> can
> be called by 2 tasks at the same time, i must write a function.
> But i may not need the return value of this function. Because what i want is 
> not really a
> function.
> What i want is "the thing in a protected object to do only read access to the 
> protected
> data
> and wich can be called by 2 tasks at the same time".
> And so i must for example call this action like this:
> My_Boolean_Return_Value_I_Dont_Want := 
> My_Protected_Object.MyProtectedFunction(..);
> It seems to strange to be true...

What do you want it to do with the value you have read? I'm not sure
why you want to "read" a value, but not do anything with the value
you have read.

Your choices are...

   access parameters to the function
   a procedure.


Dale



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-11-30 19:29 Protected Object: little question Bruno Hergott
  2001-11-30 21:15 ` Dale Stanbrough
@ 2001-11-30 22:37 ` Jeffrey Carter
  2001-12-01 10:43 ` Ehud Lamm
  2001-12-03 13:24 ` John English
  3 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Carter @ 2001-11-30 22:37 UTC (permalink / raw)


Bruno Hergott wrote:
> 
> If i want to implement an action wich does only read access to the protected data and wich
> can
> be called by 2 tasks at the same time, i must write a function.
> But i may not need the return value of this function. Because what i want is not really a
> function.
> What i want is "the thing in a protected object to do only read access to the protected
> data
> and wich can be called by 2 tasks at the same time".
> And so i must for example call this action like this:
> My_Boolean_Return_Value_I_Dont_Want := My_Protected_Object.MyProtectedFunction(..);
> It seems to strange to be true...
> 
> Or is there something i haven't understand ?

Since the function can't change the protected object, and you ignore the
return value, what's the point of calling the function?

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-11-30 21:15 ` Dale Stanbrough
@ 2001-12-01  4:00   ` Mark Lundquist
  2001-12-01 15:55     ` Nick Roberts
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lundquist @ 2001-12-01  4:00 UTC (permalink / raw)



"Dale Stanbrough" <dstanbro@bigpond.net.au> wrote in message
news:dstanbro-CBB8ED.08132901122001@mec2.bigpond.net.au...
> Bruno Hergott wrote:
>
> > If i want to implement an action wich does only read access to the
protected
> > data and wich
> > can
> > be called by 2 tasks at the same time, i must write a function.
> > But i may not need the return value of this function. Because what i
want is
> > not really a
> > function.
> > What i want is "the thing in a protected object to do only read access
to the
> > protected
> > data
> > and wich can be called by 2 tasks at the same time".
[snip]
>
> What do you want it to do with the value you have read? I'm not sure
> why you want to "read" a value, but not do anything with the value
> you have read.

I think he's saying that he has an operation that he wants to read (but not
update) state inside the PO, but it doesn't need to return anything out of
the PO.  Because the operation doesn't update protected state, he doesn't
need the exclusive (writer) access that a protected procedure gets.  He only
needs concurrent (reader) access, i.e. protected against writers but not
other readers -- the kind of access that protected functions have.

Question for the O.P.:

Why can't you write your operation outside the PO, and have a protected
function that just returns the information the operation needs?  That is,
instead of implementing your abstraction *as* a PO, embed a PO in the
implementation of the abstraction.

That said, Ada95's use of function vs. procedure this way does seem a bit
specious, maybe it was a "for lack of a better way" kind of solution.  But I
haven't read the mapping documents etc. so I have to withhold judgement :-)

-- mark








^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-11-30 19:29 Protected Object: little question Bruno Hergott
  2001-11-30 21:15 ` Dale Stanbrough
  2001-11-30 22:37 ` Jeffrey Carter
@ 2001-12-01 10:43 ` Ehud Lamm
  2001-12-03 13:24 ` John English
  3 siblings, 0 replies; 8+ messages in thread
From: Ehud Lamm @ 2001-12-01 10:43 UTC (permalink / raw)


You must use a function inside the portected object. It can return a dummy
value (a boolean TRUE for example).
If you don't want users to deal with this ugly and useless return value,
simply provide a procedure (declared otuside the p.o) that uses the function
and discards the dummy return value.

Ehud





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-12-01  4:00   ` Mark Lundquist
@ 2001-12-01 15:55     ` Nick Roberts
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Roberts @ 2001-12-01 15:55 UTC (permalink / raw)


"Mark Lundquist" <up.yerz@nospam.com> wrote in message
news:HBYN7.7398$726.3745989@news1.sttln1.wa.home.com...
> ...
> That said, Ada95's use of function vs. procedure this way does seem a bit
> specious, maybe it was a "for lack of a better way" kind of solution.  But
I
> haven't read the mapping documents etc. so I have to withhold judgement
:-)

Personally, I like it.

--
Nick Roberts







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-11-30 19:29 Protected Object: little question Bruno Hergott
                   ` (2 preceding siblings ...)
  2001-12-01 10:43 ` Ehud Lamm
@ 2001-12-03 13:24 ` John English
  2001-12-03 15:26   ` Martin Dowie
  3 siblings, 1 reply; 8+ messages in thread
From: John English @ 2001-12-03 13:24 UTC (permalink / raw)


Bruno Hergott wrote:
> 
> My question is:
> If i want to implement an action wich does only read access to the
> protected data and wich can
> be called by 2 tasks at the same time, i must write a function.
> But i may not need the return value of this function. Because what
> i want is not really a function.

I'd like to know how this can ever be necessary. The function can
only read the PO's private data, so if you aren't altering it and
you aren't interested in its value, what are you trying to do with
it?

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.comp.it.bton.ac.uk/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Protected Object: little question
  2001-12-03 13:24 ` John English
@ 2001-12-03 15:26   ` Martin Dowie
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Dowie @ 2001-12-03 15:26 UTC (permalink / raw)


"John English" <je@brighton.ac.uk> wrote in message
news:3C0B7CF4.F4C8DECA@brighton.ac.uk...
> Bruno Hergott wrote:
> >
> > My question is:
> > If i want to implement an action wich does only read access to the
> > protected data and wich can
> > be called by 2 tasks at the same time, i must write a function.
> > But i may not need the return value of this function. Because what
> > i want is not really a function.
>
> I'd like to know how this can ever be necessary. The function can
> only read the PO's private data, so if you aren't altering it and
> you aren't interested in its value, what are you trying to do with
> it?

could he be passing the (current) contents of the PO on to the 'outside'
world?..





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-12-03 15:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-30 19:29 Protected Object: little question Bruno Hergott
2001-11-30 21:15 ` Dale Stanbrough
2001-12-01  4:00   ` Mark Lundquist
2001-12-01 15:55     ` Nick Roberts
2001-11-30 22:37 ` Jeffrey Carter
2001-12-01 10:43 ` Ehud Lamm
2001-12-03 13:24 ` John English
2001-12-03 15:26   ` Martin Dowie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox