comp.lang.ada
 help / color / mirror / Atom feed
* Basic critical sections question
@ 2010-07-03 20:06 usenet
  2010-07-03 21:48 ` John B. Matthews
  2010-07-04  7:58 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 3+ messages in thread
From: usenet @ 2010-07-03 20:06 UTC (permalink / raw)


Suppose I have a multi-tasking system where different tasks may
execute a sequence like

  P1(A,B);
  P2(C,D);
  P3(E,F);

and I want to make this sequence a critical section.  What is the
typical Ada way to do this?  Would I wrap P1, P2 and P3 in a protected
object and call as follows (perhaps creating a record to hold A..F to
make things a bit cleaner)?

  PO.P(A,B,C,D,E,F);

Or if not that, what?  Thanks.



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

* Re: Basic critical sections question
  2010-07-03 20:06 Basic critical sections question usenet
@ 2010-07-03 21:48 ` John B. Matthews
  2010-07-04  7:58 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: John B. Matthews @ 2010-07-03 21:48 UTC (permalink / raw)


In article 
<71385df3-5fec-49b9-9d7a-98cb95a346ed@n20g2000prc.googlegroups.com>,
 usenet@scriptoriumdesigns.com wrote:

> Suppose I have a multi-tasking system where different tasks may 
> execute a sequence like
> 
>   P1(A,B);
>   P2(C,D);
>   P3(E,F);
> 
> and I want to make this sequence a critical section.  What is the 
> typical Ada way to do this?  Would I wrap P1, P2 and P3 in a 
> protected object and call as follows (perhaps creating a record to 
> hold A..F to make things a bit cleaner)?
> 
>   PO.P(A,B,C,D,E,F);
> 
> Or if not that, what?  Thanks.

Looks like what it was designed for. See also,

<http://www.adaic.com/standards/95rat/RAThtml/rat95-p1-2.html#9>
<http://www.adaic.com/standards/05rat/html/Rat-5-3.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: Basic critical sections question
  2010-07-03 20:06 Basic critical sections question usenet
  2010-07-03 21:48 ` John B. Matthews
@ 2010-07-04  7:58 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2010-07-04  7:58 UTC (permalink / raw)


On Sat, 3 Jul 2010 13:06:24 -0700 (PDT), usenet@scriptoriumdesigns.com
wrote:

> Suppose I have a multi-tasking system where different tasks may
> execute a sequence like
> 
>   P1(A,B);
>   P2(C,D);
>   P3(E,F);
> 
> and I want to make this sequence a critical section.  What is the
> typical Ada way to do this?

I depends on the nature of P1..P3

> Would I wrap P1, P2 and P3 in a protected
> object and call as follows (perhaps creating a record to hold A..F to
> make things a bit cleaner)?
> 
>   PO.P(A,B,C,D,E,F);
> 
> Or if not that, what?

There are many ways and solutions, starting with better design. What are
A,B,C,D,E,F. They might be made objects or put into object maintaining
their invariants when accessed concurrently.

At the low level there are four major approaches:

1. Protected operation. Used when what you do is short and non-blocking.
E.g. P1 cannot do I/O.

2. Monitor task performing desired actions. This one can perform lengthy or
blocking operations.

3. Mutexes (implemented by a protected object, mutex holder is wrapped into 
a controlled object). The mutex holder when constructed seizes the mutex
and releases it upon finalization. While the holder exists you execute the
desired actions.

4. Asynchronous monitor task. That is when you start actions entering a
rendezvous with the monitor. Then you leave the rendezvous and do something
else, while the monitor is busy executing the actions. Some time later you
engage another rendezvous to make sure that the monitor task finished the
work.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

end of thread, other threads:[~2010-07-04  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-03 20:06 Basic critical sections question usenet
2010-07-03 21:48 ` John B. Matthews
2010-07-04  7:58 ` Dmitry A. Kazakov

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