Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
 
Annotated Ada Reference Manual (Ada 202x Draft 24)Legal Information
Contents   Index   References   Search   Previous   Next 

5.6.1 Parallel Block Statements

1/5
{AI12-0119-1} [A parallel_block_statement comprises two or more handled_sequence_of_statements separated by and where each represents an independent activity that is intended to proceed concurrently with the others.]

Syntax

2/5
{AI12-0119-1} parallel_block_statement ::= 
    parallel do
       handled_sequence_of_statements
    and
       handled_sequence_of_statements
   {and
       handled_sequence_of_statements}
    end do;

Static Semantics

3/5
{AI12-0119-1} Each handled_sequence_of_statements represents a separate logical thread of control that proceeds independently and concurrently. The parallel_block_statement is complete once every one of the handled_sequence_of_statements has completed, either by reaching the end of its execution, or due to a transfer of control out of the construct by one of the handled_sequence_of_statements (see 5.1).
3.a/5
Implementation Note: {AI12-0119-1} Although each handled_sequence_of_statements of a parallel block represents a separate logical thread of control, the implementation may choose to combine two or more such logical threads of control into a single physical thread of control to reduce the cost of creating numerous physical threads of control. 

Examples

4/5
{AI12-0119-1} procedure Traverse (T : Expr_Ptr) is -- see 3.9
begin
   if T /= null and then
      T.all in Binary_Operation'Class -- see 3.9.1
   then -- recurse down the binary tree
      parallel do
         Traverse (T.Left);
      and
         Traverse (T.Right);
      and
         Ada.Text_IO.Put_Line
            ("Processing " & Ada.Tags.Expanded_Name (T'Tag));
      end do;
   end if;
end Traverse;
5/5
{AI12-0119-1} function Search (S : String; Char : Character) return Boolean is
begin
   if S'Length <= 1000 then
       -- Sequential scan
       return (for some C of S => C = Char);
   else
       -- Parallel divide and conquer
       declare
          Mid : constant Positive := S'First + S'Length/2 - 1;
       begin
          parallel do
             for C of S(S'First .. Mid) loop
                if C = Char then
                   return True;  -- Terminates enclosing do
                end if;
             end loop;
          and
             for C of S(Mid + 1 .. S'Last) loop
                if C = Char then
                   return True;  -- Terminates enclosing do
                end if;
             end loop;
          end do;
          -- Not found
          return False;
       end;
   end if;
end Search;

Extensions to Ada 2012

5.a/5
{AI12-0119-1} The parallel_block_statement is new. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe