comp.lang.ada
 help / color / mirror / Atom feed
From: "Dr. Adrian Wrigley" <amtw@linuxchip.demon.co.uk.uk.uk>
Subject: Re: Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?")
Date: Sat, 03 Mar 2007 00:00:52 GMT
Date: 2007-03-03T00:00:52+00:00	[thread overview]
Message-ID: <pan.2007.03.03.00.01.49.334@linuxchip.demon.co.uk.uk.uk> (raw)
In-Reply-To: 1i3drcyut9aaw.isde6utlv6iq.dlg@40tude.net

On Fri, 02 Mar 2007 17:32:26 +0100, Dmitry A. Kazakov wrote:

> On Fri, 02 Mar 2007 11:36:22 GMT, Dr. Adrian Wrigley wrote:
> 
>> On Thu, 01 Mar 2007 14:57:01 +0100, Dmitry A. Kazakov wrote:
>> 
>>> On Thu, 01 Mar 2007 11:22:32 GMT, Dr. Adrian Wrigley wrote:
>>> 
>>>> If you don't have multiple processors, lightweight threading is
>>>> less attractive than if you do?  Inmos/Occam/Transputer was founded
>>>> on the basis that lightweight threading was highly relevant to multiple
>>>> processors.
>>>> 
>>>> Ada has no means of saying "Do these bits concurrently, if you like,
>>>> because I don't care what the order of execution is".  And a compiler
>>>> can't work it out from the source.  If your CPU has loads of threads,
>>>> compiling code with "PAR" style language concurrency is rather useful
>>>> and easy.
>>> 
>>> But par is quite low-level. What would be the semantics of:
>>> 
>>>    declare
>>>       Thing : X;
>>>    begin
>>>       par
>>>          Foo Thing);
>>>       and
>>>          Bar Thing);
>>>       and
>>>          Baz Thing);
>>>       end par;
>>>    end;
>> 
>> Do Foo, Bar and Baz in any order or concurrently, all accessing Thing.
> 
> That's the question. If they just have an arbitrary execution order being
> mutually exclusive then the above is a kind of select with anonymous
> accepts invoking Foo, Bar, Baz. The semantics is clean.
> 
>> Roughly equivalent to doing the same operations in three separate
>> tasks.  Thing could be a protected object, if concurrent writes
>> are prohibited.  Seems simple enough!
> 
> This is a very different variant:
> 
>    declare
>       Thing : X;
>    begin
>       declare -- par
>          task Alt_1; task Alt_2; task Alt_3;
>          task body Alt_1 is
>          begin
>              Foo (Thing);
>          end Alt_1;
>          task body Alt_2 is
>          begin
>              Bar (Thing);
>          end Alt_2;
>          task body Alt_3 is
>          begin
>              Baz (Thing);
>          end Alt_3;
>       begin
>          null;
>       end; -- par
> 
> If par is a sugar for this, then Thing might easily get corrupted. The
> problem with such par is that the rules of nesting and visibility for the
> statements, which are otherwise safe, become very dangerous in the case of
> par.

This is what I was thinking.

Syntax might be even simpler:
  declare
     Thing : X;
  begin par
     Foo (Thing);
     Bar (Thing);
     Baz (Thing);
  end par;

Thing won't get corrupted if the programmed knows what they're doing!
In the case of pure functions, there is "obviously" no problem:

  declare
     Thing : X := InitThing;
  begin par
     A1 := Foo (Thing);
     A2 := Bar (Thing);
     A3 := Baz (Thing);
  end par;
  return A1+A2+A3;

In the case of procedures, there are numerous reasonable uses.
Perhaps the three procedures read Thing, and output three separate files.
Or maybe they write different parts of Thing.  Maybe they validate
different properties of Thing, and raise an exception if a fault is found.
Perhaps they update statistics stored in a protected object, not shown.

The most obvious case is if the procedures are called on different
objects.  Next most likely is if they are pure functions

> Another problem is that Thing cannot be a protected object. Clearly Foo,
> Bar and Baz resynchronize themselves on Thing after updating its parts. But
> the compiler cannot know this. It also does not know that the updates do
> not influence each other. It does not know that the state of Thing is
> invalid until resynchronization. So it will serialize alternatives on write
> access to Thing. (I cannot imagine a use case where Foo, Bar and Baz would
> be pure. There seems to always be a shared outcome which would block them.)
> Further Thing should be locked for the outer world while Foo, Bar, Baz are
> running. So the standard functionality of protected objects looks totally
> wrong here.

Could Thing be composed of protected objects?  That way updates
would be serialised but wouldn't necessarily block the other procedures.

Maybe the procedures are very slow, but only touch Thing at the end?
Couldn't they run concurrently, and be serialised in an arbitrary order
at the end?

Nothing in this problem is different from the issues of doing it with
separate tasks.  So why is this any more problematic?

The semantics I want permit serial execution in any order.  And permit
operation even with a very large number of parallel statements in
effect.  Imagine a recursive call with each level having many parallel
statements.  Creating a task for each directly would probably break.
Something like an FFT, for example.  FFT the upper and lower halves
of Thing in parallel.  Combine serially.

Exception sematics would probably differ.  Any statement excepting
would stop all other par statements(?)

The compiler should be able to generate code which generates a
reasonable number of threads, depending on the hardware being used.

>> I'm looking for something like Cilk, but even the concurrent loop
>> (JPR's for I in all 1 .. n loop?) would be a help.
> 
> Maybe, just a guess, the functional decomposition rather than statements
> could be more appropriate here. The alternatives would access their
> arguments by copy-in and resynchronize by copy-out.

Maybe you're right.  But I can't see how to glue this in with
Ada (or VHDL) semantics.
--
Adrian





  reply	other threads:[~2007-03-03  0:00 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-23  0:59 Preferred OS, processor family for running embedded Ada? Mike Silva
2007-02-23  4:41 ` Steve
2007-02-23 16:00   ` Mike Silva
2007-02-23  4:49 ` Jeffrey R. Carter
2007-02-23 13:13   ` Mike Silva
2007-02-23 13:56 ` Stephen Leake
2007-02-23 14:10   ` Mike Silva
2007-02-24 10:45     ` Stephen Leake
2007-02-24 12:27       ` Jeffrey Creem
2007-02-24 22:10         ` Dr. Adrian Wrigley
2007-02-25 13:10           ` roderick.chapman
2007-02-25 17:53             ` Jeffrey R. Carter
2007-02-25 15:08           ` Stephen Leake
2007-02-28 17:20             ` Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?") Colin Paul Gloster
2007-03-01  9:18               ` Jean-Pierre Rosen
2007-03-01 11:22               ` Dr. Adrian Wrigley
2007-03-01 11:47                 ` claude.simon
2007-03-01 13:57                 ` Dmitry A. Kazakov
2007-03-01 18:09                   ` Ray Blaak
2007-03-02 11:36                   ` Dr. Adrian Wrigley
2007-03-02 16:32                     ` Dmitry A. Kazakov
2007-03-03  0:00                       ` Dr. Adrian Wrigley [this message]
2007-03-03 11:00                         ` Dmitry A. Kazakov
2007-03-03 11:27                           ` Jonathan Bromley
2007-03-03 12:12                             ` Simon Farnsworth
2007-03-03 14:07                               ` Dr. Adrian Wrigley
2007-03-03 17:28                                 ` Pascal Obry
2007-03-03 18:11                                   ` Dmitry A. Kazakov
2007-03-03 18:31                                     ` Pascal Obry
2007-03-03 20:26                                       ` Dmitry A. Kazakov
2007-03-03 21:28                                   ` Dr. Adrian Wrigley
2007-03-03 22:00                                     ` Pascal Obry
2007-03-03 13:40                             ` Dr. Adrian Wrigley
2007-03-03 15:26                               ` Jonathan Bromley
2007-03-03 16:59                                 ` Dr. Adrian Wrigley
2007-03-05 15:36                               ` Colin Paul Gloster
2007-03-03  1:58                       ` Ray Blaak
2007-03-03  8:14                         ` Pascal Obry
2007-03-03 11:00                         ` Dmitry A. Kazakov
2007-03-03 21:13                           ` Ray Blaak
2007-03-05 19:01                             ` PAR (Was: Embedded languages based on early Ada) Jacob Sparre Andersen
2007-03-06  2:01                               ` Dr. Adrian Wrigley
2007-03-06  3:30                                 ` Randy Brukardt
2007-03-06  7:10                                   ` Ray Blaak
2007-03-06 18:05                                     ` Ray Blaak
2007-03-06  6:04                                 ` tmoran
2007-03-06  6:59                                 ` Ray Blaak
2007-03-06  7:07                                 ` Ray Blaak
2007-03-06  7:22                                 ` Martin Krischik
2007-03-06 13:18                                 ` Dr. Adrian Wrigley
2007-03-06 18:16                                   ` Ray Blaak
2007-03-06 23:49                                   ` Randy Brukardt
2007-03-07  8:59                                     ` Dmitry A. Kazakov
2007-03-07 18:26                                       ` Ray Blaak
2007-03-07 19:03                                         ` Dr. Adrian Wrigley
2007-03-07 19:55                                         ` Dmitry A. Kazakov
2007-03-07 20:17                                           ` Ray Blaak
2007-03-08 10:06                                             ` Dmitry A. Kazakov
2007-03-08 18:03                                               ` Ray Blaak
2007-03-07 20:18                                           ` Pascal Obry
2007-03-07 20:41                                             ` Dr. Adrian Wrigley
2007-03-08  5:45                                               ` Randy Brukardt
2007-03-08 10:06                                                 ` Dmitry A. Kazakov
2007-03-10  1:58                                                   ` Randy Brukardt
2007-03-10  9:11                                                     ` Dmitry A. Kazakov
2007-03-08 18:08                                                 ` Ray Blaak
2007-03-10  1:50                                                   ` Randy Brukardt
2007-03-05 15:23                   ` Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?") Colin Paul Gloster
2007-03-06  0:31                     ` Dr. Adrian Wrigley
2007-03-01 16:09                 ` Colin Paul Gloster
2007-03-01 13:23               ` Martin Thompson
2007-02-26 16:34           ` Preferred OS, processor family for running embedded Ada? Jean-Pierre Rosen
2007-02-26 21:18             ` Dr. Adrian Wrigley
2007-02-27 15:39               ` Jean-Pierre Rosen
2007-02-28 12:25                 ` Jerome Hugues
2007-02-24 19:11       ` Mike Silva
2007-02-24 13:59     ` Jacob Sparre Andersen
2007-03-01 19:32       ` Jacob Sparre Andersen
2007-03-01 20:22         ` Mike Silva
replies disabled

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