comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: Multitasking and containers
Date: Fri, 24 Nov 2006 12:02:31 GMT
Date: 2006-11-24T12:02:31+00:00	[thread overview]
Message-ID: <ulkm1hx2k.fsf@earthlink.net> (raw)
In-Reply-To: ek6bqd$prc$1@cernne03.cern.ch

Maciej Sobczak <no.spam@no.spam.com> writes:

> Paragraph 3 in Annex A says that it's OK to call any standard subprogram from
> concurrent tasks as long as the parameters do not overlap. John Barnes
> ("Progamming in Ada 2005") suggests that in order to (for example) read from
> the same container, the operations need to be protected "by using the normal
> techniques such as protected objects".

Right.


> But reading from the protected object is not mutually exclusive (many readers
> are allowed) - so where's the gain? What's the difference between concurrent
> reads of, say, a Vector via protected object vs. direct access?

The reason is a conflict between safety and flexibility, a conflict that was
resolved in favor of safety.

The container must set some internal state to indicate that Query_Element is
executing, in order to prevent you from doing things inside Query_Element that
would potentially destroy the element (such as Delete'ing it).

Even though Query_Element is technically a read-only operation, that's true
only in the logical sense, not the physical sense.  It doesn't look like
Query_Element modifies the container, but it really does modify the container,
to set some state that indicates a Query_Element is in progress.

Yes, it would seem as if it should be possible for multiple tasks to all be
reading from the container simultaneously.  But it's impossible to do that and
also satisfy the requirement that the container detect potentially harmful
manipulation of the container while Query_Element is executing.

So multiple tasks -- even tasks only calling (logically) read-only operations
-- cannot simultaneously call container operations without also synchronizing
the tasks, by wrapping the container inside a protected object, using a
critical section, etc.

-Matt



      parent reply	other threads:[~2006-11-24 12:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-24  8:51 Multitasking and containers Maciej Sobczak
2006-11-24 10:11 ` Georg Bauhaus
2006-11-24 10:19 ` Dmitry A. Kazakov
2006-11-24 10:35   ` Maciej Sobczak
2006-11-24 11:14     ` Dmitry A. Kazakov
2006-11-24 12:13       ` Matthew Heaney
2006-11-27  4:17         ` Jeffrey R. Carter
2006-11-27 10:30           ` Georg Bauhaus
2006-11-27 18:41             ` Jeffrey R. Carter
2006-11-27 18:57               ` Dmitry A. Kazakov
2006-11-27 19:45               ` Matthew Heaney
2006-11-27 21:15                 ` Simon Wright
2006-11-28  1:43                 ` Dr. Adrian Wrigley
2006-11-28  2:19                   ` Matthew Heaney
2006-11-28  8:50                     ` Dmitry A. Kazakov
2006-11-28 10:31                       ` Georg Bauhaus
2006-11-28 11:24                         ` Dmitry A. Kazakov
2006-11-29  8:51                           ` Georg Bauhaus
2006-11-28 17:12                       ` Matthew Heaney
2006-11-28 18:21                         ` Dmitry A. Kazakov
2006-11-28 19:17                           ` Matthew Heaney
2006-11-29 18:43                             ` Dmitry A. Kazakov
2006-11-29 10:14                       ` Maciej Sobczak
2006-11-29 15:50                         ` Matthew Heaney
2006-11-24 12:12     ` Matthew Heaney
2006-11-24 12:05   ` Matthew Heaney
2006-11-24 12:02 ` Matthew Heaney [this message]
replies disabled

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