comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Container reqs
Date: 18 Oct 2001 20:42:55 +0100
Date: 2001-10-18T19:42:56+00:00	[thread overview]
Message-ID: <x7vadyo68g0.fsf@smaug.pushface.org> (raw)
In-Reply-To: 3BCD2EC3.3B3C4498@free.fr

Jean-Marc Bourguet <jbourguet@free.fr> writes:

> I was probably not clear enough.  Tasks savety is not something binary,
> it's something for which there is at least five levels.
> 
> 0) the whole library can't be used by two tasks without explicit
> synchronisation because there is use of some features (global variables,
> COW datastructure build without considering tasking, ...) which make 
> it totally unfit for that use.
> 
> 1) you can work savely on different objects in different tasks but not
> access the same object in different tasks without synchronisation.
> 
> 2) you can savely have read access to one object from different tasks
> but modifying accesses must be protected explicitly from other accesses.
> 
> 3) there is a limited set of modifying accesses which can be issued
> simultaneously from different tasks.
> 
> 4) whatever you do -- trying to modify the datastructure simultaneously
> via iterators from different tasks -- is save.
> 
> From my experience,
>   * level 4 is useless because you still need synchronisation
>     for other reasons when its whole generality is needed.  Achieving it
>     has a major performance impact (every operation has to be
> protected).
> 
>   * level 3 is usefull but the set of modifying access which make sense
>     depend very much on the application.  Your example is probably the
>     only widely applicable one. Achieving this level has a important
>     performance impact.
> 
>   * level 2 can be achieved with a small performance impact: there is no
>     need for explicit synchronisation, one need simply to pay attention
>     to the datastructure used and the way it is accessed.
> 
> I think that one should aim for level 2 because:
>    - this simplify the library (no need to have tasks save and tasks
> unsave
>      version)
>    - aiming level 3 whould imply major discussion about the set of
> operations
>      needed with the risks of compromising to level 4.
>    - I whould probably still encapsulate the ADT in an other
> type/package which
>      export only the operations needed for the application with names
> related
>      to the application.

The BCs' design has two sorts of Container, called monolithic and
polylithic. The monolithic containers (eg, Queue) are self-contained
memory structures, and if I say

  Queue_2 := Queue_1;

I get a deep copy. Polylithic (Grady's word!) containers are
implemented as in-memory structures with multiple viewports, for want
of a better word, so that if I say

  List_2 := List_1;

I still have only one List; if I say

  Tail (List_2);

then List_2 points one element along from List_1. Very complicated,
and the reason I recommend people not to use BC Lists unless they
really really need that functionality.

The polylithic containers (Lists, Graphs, Binary and Multiway Trees)
can't be protected, so they're at your Level 1.

The monolithic containers can be protected using BC.Containers.Guarded:

  generic
     type Base_Container is new BC.Containers.Container with private;
     type Semaphore
     is new BC.Support.Synchronization.Semaphore_Base with private;
  package BC.Containers.Guarded is

which basically adds Seize and Release operations, so that the user
has control over where synchronization is applied. This can be applied
as an add-in to any style of container (bounded or unbounded with
storage allocator). I supply two sorts of Semaphore:

   --  A Semaphore is like a standard POSIX mutex.
   type Semaphore is new Semaphore_Base with private;

   --  A Recursive_Semaphore is like a POSIX recursive mutex; once
   --  Seized by a task, that task can Seize again; other tasks are
   --  blocked until the owning task has Released the semaphore as
   --  many times as it Seized it.
   type Recursive_Semaphore is new Semaphore_Base with private;

If your task happens to die while holding the Semaphore, tough!

The other sort of concurrency control, Synchronized, requires a lot
more work since one has to wrap the protocol of the class
concerned. So far I've done it for Queues and Maps. For Queues,

  generic
     type Queue_Base is new Abstract_Queue with private;
     type Monitor is new BC.Support.Synchronization.Monitor_Base with private;
  package BC.Containers.Queues.Synchronized is

and I supply two sorts of Monitor:

   --  Single_Monitors allow one task at a time to have access, be it
   --  for reading or writing.
   type Single_Monitor is new Monitor_Base with private;

   --  Multiple_Monitors allow multiple readers; however, when a
   --  writer owns the monitor it has exclusive access.
   type Multiple_Monitor is new Monitor_Base with private;

Again, this can wrap any style of memory management. (By the way, I
should add that this generic doesn't work with ObjectAda 7.2 (free
download). I have no idea whether it works with Apex or AdaMulti or
.., no complaints received).

The normal Queue protocol includes

   procedure Pop_Value (Q : in out Queue; Elem : out Item);
   --  Remove and return the item from the front of the queue.

which is atomic (and blocking) for the Synchronized queue; I see that
for the unsynchronized Queue a call of Pop_Value on an empty queue
will in fact raise an exception (but what else can I do?!)


What really bugs me is how to provide a multiple reader/single writer
Monitor for use with iterators.


I fully agree with Jean-Marc that containers are for implementing
things, not for inheriting from!


-S



  parent reply	other threads:[~2001-10-18 19:42 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-14 20:46 Container reqs Ehud Lamm
2001-10-14 22:00 ` Larry Kilgallen
2001-10-15 20:04   ` Ehud Lamm
2001-10-16 15:19     ` Ted Dennison
2001-10-16 19:17     ` Darren New
2001-10-14 22:52 ` James Rogers
2001-10-15  1:22   ` Darren New
2001-10-15 20:06   ` Ehud Lamm
2001-10-16 18:29     ` Stephen Leake
2001-10-17  5:55     ` Simon Wright
2001-10-15 20:15   ` Ehud Lamm
2001-10-15  6:49 ` Jeffrey Carter
2001-10-16 15:25   ` Ted Dennison
2001-10-17 12:40     ` John English
2001-10-17 13:16       ` Ted Dennison
2001-10-18 15:26         ` John English
2001-10-18 16:02           ` Ted Dennison
2001-10-17 14:17       ` Ehud Lamm
2001-10-23  8:17         ` John English
2001-10-23 14:23           ` Ehud Lamm
2001-10-23 20:07             ` Stephen Leake
2001-10-23 20:46               ` Ehud Lamm
2001-10-23 20:50               ` Ted Dennison
2001-10-23 21:18                 ` Marin David Condic
2001-10-24  8:30                   ` Ehud Lamm
2001-10-24 14:08                     ` Marin David Condic
2001-10-25 20:10                       ` Ehud Lamm
2001-10-25 21:18                         ` Marin David Condic
2001-10-25 21:25                         ` Marin David Condic
2001-10-23 21:27                 ` Larry Hazel
2001-10-23 22:03                   ` Ehud Lamm
2001-10-15 14:27 ` Ted Dennison
2001-10-15 17:47   ` Darren New
2001-10-15 20:08   ` Ehud Lamm
2001-10-17  6:08     ` Simon Wright
2001-10-18 20:52       ` Ehud Lamm
2001-10-18 22:29         ` Jeffrey Carter
2001-10-19 12:10           ` Georg Bauhaus
2001-10-19 15:36           ` Stephen Leake
2001-10-19 14:53             ` Ehud Lamm
2001-10-20 11:10               ` Simon Wright
2001-10-21 18:17               ` Stephen Leake
2001-10-22 17:02                 ` Ehud Lamm
2001-10-22 17:34                   ` David Botton
2001-10-22 18:02                     ` Ehud Lamm
2001-10-20  2:44             ` Jeffrey Carter
2001-10-21 18:24               ` Stephen Leake
2001-10-23  1:13               ` Stephen Leake
2001-10-23  2:09                 ` Jeffrey Carter
2001-10-23 13:29                   ` Ted Dennison
2001-10-24  2:26                     ` Jeffrey Carter
2001-10-24 13:54                       ` Ted Dennison
2001-10-24 14:02                         ` Lutz Donnerhacke
2001-10-24 14:24                         ` Marin David Condic
2001-10-24 19:01                         ` Stephen Leake
2001-10-25  1:40                         ` Jeffrey Carter
2001-10-15 14:39 ` Lutz Donnerhacke
2001-10-15 15:36   ` Marin David Condic
2001-10-16 18:47     ` Stephen Leake
2001-10-16 19:18       ` Marin David Condic
2001-10-15 20:13   ` Ehud Lamm
2001-10-16  8:14     ` Lutz Donnerhacke
2001-10-16  8:50       ` Ehud Lamm
2001-10-16 10:12         ` Lutz Donnerhacke
2001-10-16  9:45   ` Jean-Marc Bourguet
2001-10-16 13:20     ` Ehud Lamm
2001-10-16 15:34       ` Ted Dennison
2001-10-16 18:49         ` Stephen Leake
2001-10-17  6:02         ` Simon Wright
2001-10-16 17:21     ` Jeffrey Carter
2001-10-16 18:57       ` Ted Dennison
2001-10-16 18:59       ` Stephen Leake
2001-10-16 19:38         ` Marin David Condic
2001-10-16 20:01           ` Larry Kilgallen
2001-10-16 20:19             ` Marin David Condic
2001-10-30  6:53           ` Barry Kelly
2001-10-30 14:53             ` Marin David Condic
2001-10-30 16:14             ` Jean-Marc Bourguet
2001-10-30 16:55               ` Marin David Condic
2001-10-31  6:37                 ` Simon Wright
2001-10-30 17:45             ` Stephen Leake
2001-10-16 22:12         ` Robert*
2001-10-17  7:09       ` Jean-Marc Bourguet
2001-10-17 13:36         ` Ted Dennison
2001-10-17 14:12           ` Jean-Marc Bourguet
2001-10-17 15:15             ` Ted Dennison
2001-10-17 16:32               ` Jean-Marc Bourguet
2001-10-17 16:49                 ` Ted Dennison
2001-10-17 16:55                   ` Ehud Lamm
2001-10-18  7:39                 ` Lutz Donnerhacke
2001-10-18  9:03                   ` Jean-Marc Bourguet
2001-10-18 17:25                     ` Jeffrey Carter
2001-10-18 20:09                       ` Lutz Donnerhacke
2001-10-18 22:35                         ` Jeffrey Carter
2001-10-19  8:44                           ` Lutz Donnerhacke
2001-10-20 11:14                             ` Simon Wright
2001-10-21 16:37                               ` Paul Duquennoy
2001-10-17 17:18         ` Jeffrey Carter
2001-10-18  8:59           ` Jean-Marc Bourguet
2001-10-18 19:42         ` Simon Wright [this message]
2001-10-18 20:55           ` Ehud Lamm
2001-10-22  6:46       ` Kenneth Almquist
2001-10-22  8:04         ` mike
2001-10-22  8:42           ` Lutz Donnerhacke
2001-10-22 16:30         ` Jeffrey Carter
2001-10-22 17:14           ` Ehud Lamm
2001-10-16 11:37 ` Jean-Marc Bourguet
2001-10-16 13:23   ` Ehud Lamm
2001-10-16 13:39     ` Jean-Marc Bourguet
2001-10-16 15:36     ` Vincent Marciante
2001-10-16 16:15       ` Pat Rogers
2001-10-16 19:04     ` Stephen Leake
2001-10-16 15:53   ` Ted Dennison
2001-10-16 15:58     ` Jean-Marc Bourguet
replies disabled

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