comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: How to terminate all running tasks?
  2020-06-10 12:12  7% ` Niklas Holsti
@ 2020-06-10 12:29  4%   ` Niklas Holsti
  0 siblings, 0 replies; 33+ results
From: Niklas Holsti @ 2020-06-10 12:29 UTC (permalink / raw)


On 2020-06-10 15:12, Niklas Holsti wrote:

> and in the main subprogram, instead of the null statement and the 
> exception handler:
> 
>     Ada.Synchronous_Task_Control.Suspend_Until_True (solution_found);
>     abort p6p;
>     abort p6m;

Just an addendum: to make sure that the main subprogram runs, and is not 
starved by a child task that is still searching for a solution, you may 
want to make the priorities of the child tasks lower than the priority 
of the main subprogram (the environment task).

And a further note: generally one should avoid aborting tasks, as that 
easily leads to messy race conditions. Better to have the tasks 
terminate by themselves. For example, each of the search tasks could now 
and then call Ada.Synchronous_Task_Control.Current_State 
(solution_found) and terminate itself (exit the loop) if the result is True.

-- 
Niklas Holsti

niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[relevance 4%]

* Re: How to terminate all running tasks?
  @ 2020-06-10 12:12  7% ` Niklas Holsti
  2020-06-10 12:29  4%   ` Niklas Holsti
  0 siblings, 1 reply; 33+ results
From: Niklas Holsti @ 2020-06-10 12:12 UTC (permalink / raw)


On 2020-06-10 14:14, Gilbert Gosseyn wrote:
> Hi,

It would be easier to understand your post if you started with the 
explanation and question, rather than throwing a bunch of uncommented 
code at the reader.

> -- package spezification
> package packp6 is
>     procedure tp6pm(N : Long_Integer);
> end packp6;
> 
> -- package body
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Task_Identification;
> package body packp6 is
>     procedure tp6pm(N : Long_Integer) is
>        use Ada.Task_Identification;
>        package LIO is new Integer_IO(Long_Integer);
>        solution_found : exception;
> 
>        task p6p;
>        task p6m;
> 
>        task body p6p is
>           pp,i : Long_Integer := 0;
>        begin
>           loop
>              i := i+1;
>              pp := 6*i+1;
>              if N mod pp = 0 then
>                 new_line;put("pp= ");LIO.put(pp);
>                 raise solution_found;
>              end if;
>           end loop;


This is the last point at which you can handle the "raise" above. If 
there is no handler here, WITHIN task p6p, the exception will try to 
propagate out of the task, which will terminate the task and STOP the 
propagation of the exception.

>        end p6p;
> 
>        task body p6m is
>           pm,i : Long_Integer := 0;
>        begin
>           loop
>              i := i+1;
>              pm := 6*i-1;
>              if N mod pm = 0 then
>                 new_line;put("pm= ");LIO.put(pm);
>                 raise solution_found;
>              end if;
>           end loop;


Same comment as above.

>        end p6m;
>     begin
>        null;
>     exception
>        when solution_found =>


This handler is never entered, because the "null" statement above does 
not raise solution_found.

>           Abort_Task(p6p'Identity);
>           Abort_Task(p6m'Identity);
>     end tp6pm;
> end packp6;


    [snip]

> When in a task the exception solution_found is raised, then I want
> all running tasks to be terminated immediately.

It is not possible to use an exception, raised in a task, to signal 
something outside the task in that way.

> Apparently this does not happen. How to improve?


You must use some other way to inform the main subprogram that a 
solution has been found. There are may ways, but for example you can use 
an synchronization object as follows:

    with Ada.Synchronous_Task_Control;
    ...
    solution_found : Ada.Synchronous_Task_Control.Suspension_Object;
    ...
    task body p6p
       ...
       Ada.Synchronous_Task_Control.Set_True (solution_found);
       -- Instead of the "raise".
    ...
    same for task p6m

and in the main subprogram, instead of the null statement and the 
exception handler:

    Ada.Synchronous_Task_Control.Suspend_Until_True (solution_found);
    abort p6p;
    abort p6m;

-- 
Niklas Holsti

niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[relevance 7%]

* Re: Ravenscar - release multiple tasks when an event occurs
  2020-05-05 16:02  0%   ` Simon Wright
@ 2020-05-05 16:16  0%     ` Niklas Holsti
  0 siblings, 0 replies; 33+ results
From: Niklas Holsti @ 2020-05-05 16:16 UTC (permalink / raw)


On 2020-05-05 19:02, Simon Wright wrote:
> Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
> 
>> On 2020-05-03 13:43, Simon Wright wrote:
>>> I have several sensor tasks (in general, 2 at the moment) which will of
>>> course be created and start execution during elaboration.
>>
>> Depends on the value specified for pragma
>> Partition_Elaboration_Policy. If it is Sequential, the tasks start
>> only after (most of) elaboration is completed -- RM H.6.
> 
> Indeed, I'd forgotten that.
> 
> The top level of the code has SPARK_Mode, and I'm fairly sure that
> requires Sequential. I have Partition_Elaboration_Policy (Sequential),
> anyway.
> 
>>> I'd like to ensure that they don't actually start reading and reporting
>>> input data until the system is in a state to receive them.
>>
>> How/when does the system reach that state? At end of elaboration, or
>> at some much later time? Should other tasks execute before that state
>> is reached?
> 
> Some later time, and indeed other tasks do execute first.

Ok. I had in mind a solution where the elaboration of the sensor-task 
packages is delayed until some other elaboration sets up the good state 
(even if it takes a while), but if you need other tasks for that, and 
have Sequential task elaboration, this solution is not possible.

>>> With the Ravenscar profile it's not obvious how to do this (only one
>>> entry per PO, only one task allowed to queue).
>>
>> You can of course create a special protected object for each sensor
>> task that has an entry "wait until system in good state" and a
>> procedure "declare system in good state" to open that entry.
>>
>> Or you could do the same with Suspension_Objects from
>> Ada.Synchronous_Task_Control (but Gnat implements them as protected
>> objects anyway, I think).
> 
> I think those suffer from the same problem.

Yes, you need a different Suspension_Object for each task to be 
suspended (concurrently).

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[relevance 0%]

* Re: Ravenscar - release multiple tasks when an event occurs
  2020-05-03 11:50  4% ` Niklas Holsti
@ 2020-05-05 16:02  0%   ` Simon Wright
  2020-05-05 16:16  0%     ` Niklas Holsti
  0 siblings, 1 reply; 33+ results
From: Simon Wright @ 2020-05-05 16:02 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 2020-05-03 13:43, Simon Wright wrote:
>> I have several sensor tasks (in general, 2 at the moment) which will of
>> course be created and start execution during elaboration.
>
> Depends on the value specified for pragma
> Partition_Elaboration_Policy. If it is Sequential, the tasks start
> only after (most of) elaboration is completed -- RM H.6.

Indeed, I'd forgotten that.

The top level of the code has SPARK_Mode, and I'm fairly sure that
requires Sequential. I have Partition_Elaboration_Policy (Sequential),
anyway.

>> I'd like to ensure that they don't actually start reading and reporting
>> input data until the system is in a state to receive them.
>
> How/when does the system reach that state? At end of elaboration, or
> at some much later time? Should other tasks execute before that state
> is reached?

Some later time, and indeed other tasks do execute first.

>> With the Ravenscar profile it's not obvious how to do this (only one
>> entry per PO, only one task allowed to queue).
>
> You can of course create a special protected object for each sensor
> task that has an entry "wait until system in good state" and a
> procedure "declare system in good state" to open that entry.
>
> Or you could do the same with Suspension_Objects from
> Ada.Synchronous_Task_Control (but Gnat implements them as protected
> objects anyway, I think).

I think those suffer from the same problem.

^ permalink raw reply	[relevance 0%]

* Re: Ravenscar - release multiple tasks when an event occurs
  @ 2020-05-03 11:50  4% ` Niklas Holsti
  2020-05-05 16:02  0%   ` Simon Wright
  0 siblings, 1 reply; 33+ results
From: Niklas Holsti @ 2020-05-03 11:50 UTC (permalink / raw)


On 2020-05-03 13:43, Simon Wright wrote:
> I have several sensor tasks (in general, 2 at the moment) which will of
> course be created and start execution during elaboration.

Depends on the value specified for pragma Partition_Elaboration_Policy. 
If it is Sequential, the tasks start only after (most of) elaboration is 
completed -- RM H.6.

> I'd like to ensure that they don't actually start reading and reporting
> input data until the system is in a state to receive them.

How/when does the system reach that state? At end of elaboration, or at 
some much later time? Should other tasks execute before that state is 
reached?

> With the Ravenscar profile it's not obvious how to do this (only one
> entry per PO, only one task allowed to queue).

You can of course create a special protected object for each sensor task 
that has an entry "wait until system in good state" and a procedure 
"declare system in good state" to open that entry.

Or you could do the same with Suspension_Objects from 
Ada.Synchronous_Task_Control (but Gnat implements them as protected 
objects anyway, I think).

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[relevance 4%]

* Re: How to simulate semaphores with Ada's tasks?
  @ 2016-08-25  7:55  5% ` G.B.
  0 siblings, 0 replies; 33+ results
From: G.B. @ 2016-08-25  7:55 UTC (permalink / raw)


On 25.08.16 02:41, Andrew Shvets wrote:
> From what I've read, tasks do not have semaphores that can permit it to lock a piece of memory and prevent it from being accessed, is this correct?
>
> If so, then the best possible way to simulate this is to have tasks send messages to one another and synchronize when something is locked/unlocked.  Is there a better approach?
>

The thing is called Suspension_Object in Ada, see
Ada.Synchronous_Task_Control (RM D.10).

But, as others have said, it might be a good idea to
consider the use case and arrive at a protected resource.


-- 
"HOTDOGS ARE NOT BOOKMARKS"
Springfield Elementary teaching staff


^ permalink raw reply	[relevance 5%]

* ANN: Cortex GNAT RTS 20160522
@ 2016-05-22 14:20  3% Simon Wright
  0 siblings, 0 replies; 33+ results
From: Simon Wright @ 2016-05-22 14:20 UTC (permalink / raw)


Available at
https://sourceforge.net/projects/cortex-gnat-rts/files/20160522/

This release includes GNAT Ada Run Time Systems (RTSs) based
on FreeRTOS (http://www.freertos.org) and targeted at boards with
Cortex-M3, -M4, -M4F MCUs (Arduino Due from http://www.arduino.org,
the STM32F4-series evaluation boards from STMicroelectronics at
http://www.st.com).

In each case, the board support for the RTS (configuration for size
and location of Flash, RAM; clock initialization; interrupt naming) is
in $RTS/adainclude. Support for the on-chip peripherals is also
included, in Ada spec files generated by SVD2Ada
(https://github.com/AdaCore/svd2ada).

The Ada source is either original or based on FSF GCC (mainly 4.9.1,
some later releases too).

(1) arduino-due is a Ravenscar-style RTOS based on FreeRTOS from
    http://www.freertos.org for the Arduino Due.

    See arduino-due/COPYING* for licensing terms.

    On-chip peripheral support in atsam3x8e/.

    Tests in test-arduino-due/.

(2) stm32f4 is a Ravenscar-style RTOS based on FreeRTOS from
    http://www.freertos.org for the STM32F4-DISC* board.

    See stm32f4/COPYING* for licensing terms.

    On-chip peripheral support in stm32f40x/.

    Tests in test-stm32f4/.

(3) stm32f429i is a Ravenscar-style RTOS based on FreeRTOS from
    http://www.freertos.org for the STM32F429I-DISC* board.

    See stm32f429i/COPYING* for licensing terms.

    On-chip peripheral support in stm32f429x/.

    Tests in test-stm32f429i/.

In this release,

* There is no longer any dependence on the STMicroelectronics'
  STM32Cube package.

* The support for on-chip peripherals is limited to the
  SVD2Ada-generated spec files. The AdaCore 'bareboard' software
  (currently https://github.com/AdaCore/bareboard, but a name change
  is under consideration) supports the STM32 line.

* Tasking no longer requires an explicit start
  (https://sourceforge.net/p/cortex-gnat-rts/tickets/5/).

* Locking in interrupt-handling protected objects no longer inhibits
  all interrupts, only those of equal or lower priority
  (https://sourceforge.net/p/cortex-gnat-rts/tickets/18/).

The standard packages included (there are more, implementation-specific,
ones) are:

Ada
Ada.Containers
Ada.Containers.Bounded_Hashed_Maps
Ada.Containers.Bounded_Vectors
Ada.Exceptions
Ada.IO_Exceptions
Ada.Interrupts
Ada.Interrupts.Names
Ada.Iterator_Interfaces
Ada.Real_Time
Ada.Streams
Ada.Synchronous_Task_Control
Ada.Tags
Ada.Task_Identification
Interfaces
Interfaces.C
Interfaces.C.Strings
System
System.Assertions
System.Address_To_Access_Conversions
System.Storage_Elements
GNAT
GNAT.Source_Info


^ permalink raw reply	[relevance 3%]

* ANN: Cortex GNAT RTS 20160314
@ 2016-03-14 17:42  4% Simon Wright
  0 siblings, 0 replies; 33+ results
From: Simon Wright @ 2016-03-14 17:42 UTC (permalink / raw)


At https://sourceforge.net/projects/cortex-gnat-rts/files/20160314/.

This release includes

* an RTS for the Arduino Due, arduino-due, and a minimal BSP,
  arduino-due-bsp.

* an RTS for the STM32F429I-DISCO, stm32f429i-disco-rtos, based on
  STMicroelectronics' STM32Cube package and FreeRTOS, and a
  corresponding partial BSP, stm32f429i-disco-bsp.

* an RTS for the STM32F429I-DISCO, stm32f429i, based on FreeRTOS, with
  a set of peripheral definition packages created by SVD2Ada.

In this release,

* the Containers support generalized iteration ("for all E of C
  loop"). Note, this is achieved by removing tampering checks. While
  tampering errors are rare, it would be as well to check algorithms
  using a fully-featured desktop compiler.

The standard packages included (there are more, implementation-specific,
ones) are:

Ada
Ada.Containers
Ada.Containers.Bounded_Hashed_Maps
Ada.Containers.Bounded_Vectors
Ada.Exceptions
Ada.IO_Exceptions
Ada.Interrupts
Ada.Interrupts.Names
Ada.Iterator_Interfaces
Ada.Real_Time
Ada.Streams
Ada.Synchronous_Task_Control
Ada.Tags
Ada.Task_Identification
Interfaces
Interfaces.C
Interfaces.C.Strings
System
System.Assertions
System.Address_To_Access_Conversions
System.Storage_Elements
GNAT
GNAT.Source_Info


^ permalink raw reply	[relevance 4%]

* ANN: Cortex GNAT RTS 20160207
@ 2016-02-07 22:45  4% Simon Wright
  0 siblings, 0 replies; 33+ results
From: Simon Wright @ 2016-02-07 22:45 UTC (permalink / raw)


This release is at Sourceforge[1].

This release includes an RTS for the Arduino Due, arduino-due, and a
minimal BSP, arduino-due-bsp.

For the STM32F429I-DISCO, there is one RTS, stm32f429i-disco-rtos, and
one BSP, stm32f429i-disco-bsp.

In this release,

* the Containers support generalized iteration ("for all E of C
  loop"). Note, this is achieved by removing tampering checks. While
  tampering errors are rare, it would be as well to check algorithms
  using a fully-featured desktop compiler.

* FreeRTOS is configured to detect stack overflow (if it is detected,
  the RTS loops inside vApplicationStackOverflowHook()).

The standard packages included (there are more,
implementation-specific, ones) are:

   Ada
   Ada.Containers
   Ada.Containers.Bounded_Hashed_Maps
   Ada.Containers.Bounded_Vectors
   Ada.Exceptions
   Ada.IO_Exceptions
   Ada.Interrupts
   Ada.Interrupts.Names
   Ada.Iterator_Interfaces
   Ada.Real_Time
   Ada.Streams
   Ada.Synchronous_Task_Control
   Ada.Tags
   Ada.Task_Identification
   Interfaces
   Interfaces.C
   Interfaces.C.Strings
   System
   System.Assertions
   System.Address_To_Access_Conversions
   System.Storage_Elements
   GNAT
   GNAT.Source_Info

The software is supplied built with for debugging (-g) and with suitable
optimisation (-Og), using GNAT GPL 2015 on Mac OS X (it should work
out of the box with a Linux-hosted GNAT GPL 2015 cross-compiler, but
will need recompiling for another compiler version).

[1] https://sourceforge.net/projects/cortex-gnat-rts/files/20160207/


^ permalink raw reply	[relevance 4%]

* Re: can someone help me with this code (explanation)
  @ 2014-09-26 10:24  5%                 ` G.B.
  0 siblings, 0 replies; 33+ results
From: G.B. @ 2014-09-26 10:24 UTC (permalink / raw)


On 26.09.14 09:58, J-P. Rosen wrote:
> Le 26/09/2014 09:04, Björn Lundin a écrit :
>> Or by using a protected object as a semaphore
>>
> But why? It's so simpler with a task:

It also centralizes I/O to one task, unlike a solution using
locking in each task that takes hold of a PO or, alternatively,
a Suspension_Object:

    procedure Print (Message : String) is
       use Ada.Text_IO, Ada.Synchronous_Task_Control;
    begin
       Suspend_Until_True (Lock);
       Put_Line (Message);
       Flush;
       Set_True (Lock);
    end Print;



^ permalink raw reply	[relevance 5%]

* Re: Freezing a task
  @ 2011-11-19  7:37  4%     ` anon
  0 siblings, 0 replies; 33+ results
From: anon @ 2011-11-19  7:37 UTC (permalink / raw)


In some programming circles, the "main procedure" is also called the parent. 

And tasks without the "Terminate" statement some times will continue to 
execute, even when the parent aka "main procedure" dies. One reason for 
the disliked "Abort" statement.

Two examples of tasks that do not contain "terminate" statement are 
servers and tasking device drivers. For the task to stop, these tasks 
must be setup to handle a "Stop" type of call to interrupt the process 
or another routine may have to use the "Abort" statement.

Of course, there always the "Ada.Synchronous_Task_Control but that's
a more involved process. And a fully functional version of the package 
Ada.Asynchronous_Task_Control is not supply in the general release 
of GNAT version of Ada.

In my example the one thing I did not include was the single to 
multiple layers of exceptions that could be added.




In <cfdf14ce-1304-4c52-a8ec-3cfbd51669ee@g21g2000yqc.googlegroups.com>, Anh Vo <anhvofrcaus@gmail.com> writes:
>On Nov 17, 11:24=A0pm, a...@att.net wrote:
>> --
>> -- =A0Complete Program
>> --
>>
>> with Text_IO ;
>>
>> procedure u is
>>
>> =A0 use Text_IO ;
>>
>> =A0 task type test is
>> =A0 =A0 =A0 entry Start ; =A0 =A0-- initialize and start task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- and task can die if par=
>ent stops
>>
>> =A0 =A0 =A0 entry Wait ; =A0 =A0 -- Send task to sleep for a while
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- and task can die if par=
>ent stops
>>
>> =A0 =A0 =A0 entry Continue ; -- wake up task
>> =A0 =A0 =A0 entry Stop ; =A0 =A0 -- stops and kill task
>> =A0 end test ;
>>
>> =A0 task body test is
>>
>> =A0 =A0 =A0 Count : Integer ;
>> =A0 =A0 begin
>> =A0 =A0 =A0 -- =A0Initialize task
>> =A0 =A0 =A0 Count :=3D 0 =A0;
>> =A0 =A0 =A0 Outer_Loop : loop
>> =A0 =A0 =A0 =A0 select
>> =A0 =A0 =A0 =A0 =A0 -- =A0start task
>> =A0 =A0 =A0 =A0 =A0 accept Start ;
>> =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Start" ) ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 Main_Loop : loop
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 select
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0pause task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Wait ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Wait" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 New_Line ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 select
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0sofware wake up task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Continue ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Continue" ) ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0software exit while in wait mod=
>e
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Stop ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Stop" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit Outer_Loop ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0exit if parent fails while in w=
>ait mode
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 terminate ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end select ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0software exit (abort) while in normal
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0execution mode
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Stop ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Stop" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit Outer_Loop ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- - - - - - - - - - - --
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0Main Tasking Code =A0--
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- - - - - - - - - - - --
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put ( "Testing" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put ( Integer'Image ( Count ) ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 New_Line ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Count :=3D Count + 1 ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 end select ;
>> =A0 =A0 =A0 =A0 =A0 end loop Main_Loop ;
>>
>> =A0 =A0 =A0 =A0 -- =A0exit if parent fails
>> =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 terminate ;
>> =A0 =A0 =A0 =A0 end select ;
>> =A0 =A0 =A0 end loop Outer_Loop ;
>> =A0 =A0 =A0 Put_Line ( "Task has Terminated" ) ;
>> =A0 =A0 end test ;
>>
>> =A0testing_task =A0 =A0 =A0: test ;
>>
>> begin
>> =A0 Put_Line ( "Start Tasking" ) ;
>> =A0 New_Line ;
>> =A0 --
>> =A0 testing_task.Start ;
>> =A0 delay ( 0.01 ) ;
>> =A0 testing_task.Wait ;
>> =A0 delay ( 1.0 ) ;
>> =A0 testing_task.Continue ;
>> =A0 delay ( 0.01 ) ;
>> =A0 testing_task.Wait ;
>> =A0 --
>> =A0 delay ( 1.0 ) ;
>> =A0 testing_task.Stop ;
>> =A0 delay ( 0.5 ) ;
>> =A0 New_Line ;
>> end u ;
>
>I am not sure what was meant by couple of annotated comments
>mentioning parent fails. Normally, tasks are declared at library
>level. Thus, they will terminate when the main program terminates. In
>this particular example, the task will terminate when the main
>procedure terminates.
>
>Anh Vo




^ permalink raw reply	[relevance 4%]

* Re: Freezing a task
  2011-11-17 17:13  5% ` Adam Beneschan
  2011-11-17 18:01  0%   ` AdaMagica
@ 2011-11-18  1:22  0%   ` Rego, P.
  1 sibling, 0 replies; 33+ results
From: Rego, P. @ 2011-11-18  1:22 UTC (permalink / raw)


> Aside from the other suggestions, you might want to look into
> Ada.Synchronous_Task_Control and Ada.Asynchronous_Task_Control.

I shall go to take a look on it. Thank you.




^ permalink raw reply	[relevance 0%]

* Re: Freezing a task
  2011-11-17 17:13  5% ` Adam Beneschan
@ 2011-11-17 18:01  0%   ` AdaMagica
  2011-11-18  1:22  0%   ` Rego, P.
  1 sibling, 0 replies; 33+ results
From: AdaMagica @ 2011-11-17 18:01 UTC (permalink / raw)


> Aside from the other suggestions, you might want to look into
> Ada.Synchronous_Task_Control and Ada.Asynchronous_Task_Control.

Synch. might do the job, asynch is (for GNAT) only implemented on bare
boards.



^ permalink raw reply	[relevance 0%]

* Re: Freezing a task
  @ 2011-11-17 17:13  5% ` Adam Beneschan
  2011-11-17 18:01  0%   ` AdaMagica
  2011-11-18  1:22  0%   ` Rego, P.
    1 sibling, 2 replies; 33+ results
From: Adam Beneschan @ 2011-11-17 17:13 UTC (permalink / raw)


On Nov 17, 7:33 am, "Rego, P." <pvr...@gmail.com> wrote:
> Is is possible to freeze a task?
>
> I mean, if I have a task
>
> task body My_Task is
> begin
>   accept Start;
>   loop
>     Put ("1");
>     Put ("2");
>     Put ("3");
>     ...
>     Put ("n");
>   end loop;
> end My_Task;
>
> is there a way that I can "freeze" the task in its current state? If, for instance, the execution finished executing Put ("2");, how can I freeze it and later I can turn it to continue? I want to provoque a freeze from outside the task, and also from outside, order it to continue.
>
> I could sure implement, if I had the spec like
>
> type State_Type is
>   (RUN,
>    FROZEN);
>
> task type My_Task (State : State_Type) is
>    entry Start;
> end My_Task;
> --
>
> the body:
>
> task body My_Task is
> begin
>   accept Start;
>   loop
>     Put ("1");
>     Put ("2");
>     Put ("3");
>     ...
>     Put ("n");
>
>     loop
>      if State = RUN then exit; end if;
>     end loop;
>   end loop;
> end My_Task;
>
> but it would not be the case because I had to wait for the nth Put instruction line (i.e., the task would not be actually frozen, because the inside loop would be running).
>
> And T.E.D. from stackoverflow suggested me something that I could infer as
>
> task type My_Task (Start : Start_Type) is
>    entry Start;
>    entry Run;
> end My_Task
> --
> task body My_Task is
> begin
>   accept Start;
>   loop
>     Put ("1");
>     Put ("2");
>     Put ("3");
>     ...
>     Put ("n");
>
>     if State = FROZEN then
>        accept Run;
>        State := RUN;
>     end if;
>   end loop;
> end My_Task;
>
> Is there a more elegant way to do this? Maybe some procedure My_Task.FreezeNow in a unknown (by me) package? Thanks

Aside from the other suggestions, you might want to look into
Ada.Synchronous_Task_Control and Ada.Asynchronous_Task_Control.  I'm
not really clear on what you're trying to accomplish, so it's hard for
me to say whether those are appropriate solutions for you.  I think
that the other methods that have been suggested--an entry call on
another task or on a protected object, or an ACCEPT statement--would
be preferable if they get the job done.

                               -- Adam



^ permalink raw reply	[relevance 5%]

* Re: [Ravenscar] run tasks on events
  @ 2008-05-30  7:26  3% ` Niklas Holsti
  0 siblings, 0 replies; 33+ results
From: Niklas Holsti @ 2008-05-30  7:26 UTC (permalink / raw)


Sebastian Hanigk wrote:
> Hello,
> 
> sorry if this is a stupid question, but as newcomer to Ada I've stumbled
> over the following problem: having read a bit on HAL/S which has task
> scheduling depending on signals and conditions, I'm a bit at loss how to
> implement such functionality in Ada under the Ravenscar profile (no
> dynamic task spawning).

Note that Ravenscar has other restrictions, too, which means that 
some of the answers you got are not valid:

jimmaureenrogers@worldnet.att.net wrote:
 > ...
 > You can create a task which suspends until the ascent/descent
 > phase. Simply have the task suspend on an accept statement.
 > The task will complete its execution upon execution of a
 > rendezvous associated with the accept statement.

The Ravenscar profile forbids task entries and rendezvous, so the 
above is not possible. Ravenscar tasks can be controlled only by 
protected object entries and suspension objects from 
Ada.Synchronous_Task_Control.

 >> ahab <ahabe...@gmail.com> writes:
 >>
 >>> Have the task immediately call a suspension object or a
 >>> protected entry.

Both methods work.

 > On May 29, 3:31 am, Sebastian Hanigk <han...@in.tum.de> wrote:
 >> ...
 >> Hmm, this works only for one task if I'm not mistaken (a
 >> suspension object allows only one blocking call to
 >> Suspend_Until_True at the same time...

That's right, so you would need one suspension object per task, 
whether or not the Ravenscar profile is in effect.

 >> a protected entry seems to have similar constraints).

This is true only under the Ravenscar profile, because of the 
Ravenscar restriction that Max_Entry_Queue_Length is 1. In 
unrestricted Ada, many tasks can be waiting on the same entry.

Anh Vo wrote:
 > It is not true. Protected entry, implemented in Transient
 > Signals for example, can suspend/release multiple tasks.

True in unrestricted Ada (an entry queue can hold many tasks), 
false under the Ravenscar profile (maximum one task waiting on an 
entry). If you use protected objects to trigger tasks, you need one 
object per task.

Note that under the Ravenscar profile, one generally needs one 
protected object per (sporadic) task, anyway, to trigger that task 
when required. This protected object can easily be extended with a 
boolean control variable such that the entry triggers the task only 
in the appropriate modes or phases.

On the other hand, personally I'm a bit skeptical about triggering 
certain tasks only in certain modes. I suspect that most systems 
could as well keep the same set of active tasks, and just make the 
tasks do different things in different modes, using plain old "if 
then else" in the task body.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[relevance 3%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-04-02 14:59  4%                             ` (see below)
  2008-04-04  6:36  6%                               ` Ole-Hjalmar Kristensen
@ 2008-04-15 12:05  5%                               ` Ole-Hjalmar Kristensen
  1 sibling, 0 replies; 33+ results
From: Ole-Hjalmar Kristensen @ 2008-04-15 12:05 UTC (permalink / raw)


After reading your post about use of suspension objects, I looked in
the RM to see what guarantees we have about the effect of sharing
variables between tasks synchronized with suspension objects. I
completely agree that to work reliably on a multiprocessor the
suspension operations *has* to impose a memory barrier, but I was
unable to find any explicit statement about sharing variables
synchronized with suspension objects.

The sections I have reproduced below is the closest I could get. Since
Suspend_Until_True is potentially blocking, it *could* be signaled (as
defined in 9.10), but I find it strange that it is not mentioned
explicitly. Also, the statement "can be used for two-stage suspend
operations and as a simple building block for implementing
higher-level queues", seems to indicate that the intent indeed is to
be able to use suspension objects to synchronize access to shared
variables. Comments, anyone?

From the AARM:

9.10 Shared Variables

 9.a    Reason:  The underlying principle here is that for one action to
        ``signal'' a second, the second action has to follow a
        potentially blocking operation, whose blocking is dependent on
        the first action in some way.  Protected procedures are not
        potentially blocking, so they can only be "signalers," they
        cannot be signaled.

and 

D.10 Synchronous Task Control

1   [This clause describes a language-defined private semaphore (suspension
object), which can be used for two-stage suspend operations and as a simple
building block for implementing higher-level queues.]
...
9   The procedure Suspend_Until_True blocks the calling task until the state
of the object S is true; at that point the task becomes ready and the state
of the object becomes false.

10   {potentially blocking operation [Suspend_Until_True]} {blocking,
potentially [Suspend_Until_True]} {Program_Error (raised by failure of
run-time check)} Program_Error is raised upon calling Suspend_Until_True if
another task is already waiting on that suspension object.  Suspend_Until_
True is a potentially blocking operation (see 9.5.1).


>>>>> "(b" == (see below) <yaldnif.w@blueyonder.co.uk> writes:

<snip>

    (b> Following on my second post to the point, I was reminded of the package
    (b> Ada.Synchronous_Task_Control, which must also impose memory barriers is it
    (b> is to work reliably on a multiprocessor; so I tried that in my Simpson's
    (b> algorithm test as well. Here is the code:

    >> with Ada.Synchronous_Task_Control;
    >> package body Wait_Free_Atomicity is
    >> 
    >> procedure Sync is
    >> use Ada.Synchronous_Task_Control;
    >> Sema : Suspension_Object;
    >> Bool : Boolean := Current_State(Sema); -- either this
    >> begin
    >> -- Set_True(Sema);                     -- or
    >> -- Suspend_Until_True(Sema);           -- this
    >> end Sync;
    >> 
    >> procedure Update (Atomic_Item : in out an_Atomic; Item : in  an_Item) is
    >> Row : constant a_Bistate := not Atomic_Item.Last_Row_Inspected;
    >> Col : constant a_Bistate := not Atomic_Item.Last_Column_Updated(Row);
    >> begin
    >> Atomic_Item.Data_Slot_Matrix(Row, Col) := Item;
    >> Atomic_Item.Last_Column_Updated(Row) := Col;
    >> Atomic_Item.Last_Row_Updated := Row;
    >> Sync;
    >> end Update;
    >> 
    >> procedure Inspect (Atomic_Item : in out an_Atomic; Item : out an_Item) is
    >> Row : constant a_Bistate := Atomic_Item.Last_Row_Updated;
    >> Col : a_Bistate;
    >> pragma Atomic (Col);
    >> begin
    >> Atomic_Item.Last_Row_Inspected := Row;
    >> Col  := Atomic_Item.Last_Column_Updated(Row);
    >> Item := Atomic_Item.Data_Slot_Matrix(Row, Col);
    >> Sync;
    >> end Inspect;
    >> 
    >> end Wait_Free_Atomicity;

    (b> It works nicely, and is an order of magnitude faster than a protected
    (b> object:

    (b> 20_000_000 updates

    (b> with Suspend_Until_True sync:
    (b> No consistency failures.
    (b>         7.30 real        14.14 user         0.04 sys

    (b> with Current_State sync:
    (b> No consistency failures.
    (b>         3.57 real         6.97 user         0.02 sys

    (b> -- 
    (b> Bill Findlay
    (b> <surname><forename> chez blueyonder.co.uk



-- 
   C++: The power, elegance and simplicity of a hand grenade.



^ permalink raw reply	[relevance 5%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-04-04 17:36  0%                                   ` Georg Bauhaus
@ 2008-04-04 17:40  0%                                     ` (see below)
  0 siblings, 0 replies; 33+ results
From: (see below) @ 2008-04-04 17:40 UTC (permalink / raw)


On 04/04/2008 18:36, in article 1207330618.23925.2.camel@K72, "Georg
Bauhaus" <rm.plus-bug.tsoh@maps.futureapps.de> wrote:

> 
> On Fri, 2008-04-04 at 14:56 +0100, (see below) wrote:
>> On 04/04/2008 07:36, in article wvbry77uxh19.fsf@astra06.norway.sun.com,
>> "Ole-Hjalmar Kristensen"
>> <ole-hjalmar.kristensen@substitute_employer_here.com> wrote:
>> 
>>> Interesting. I had not thought of Ada.Synchronous_Task_Control.  Apart
>>> from that, I agree that a "best effort" implementation of standard
>>> library like the membar_ops and atomic_ops which are part of the
>>> Solaris C library would likely be sufficient.
>> 
>> Is there online documentation/code for that library?
> 
> docs.sun.com has sometimes been a good starting point.
> http://docs.sun.com/app/docs/doc/819-2256/membar-ops-9f?a=view

Thank, that's handy.

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[relevance 0%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-04-04 13:56  0%                                 ` (see below)
@ 2008-04-04 17:36  0%                                   ` Georg Bauhaus
  2008-04-04 17:40  0%                                     ` (see below)
  0 siblings, 1 reply; 33+ results
From: Georg Bauhaus @ 2008-04-04 17:36 UTC (permalink / raw)



On Fri, 2008-04-04 at 14:56 +0100, (see below) wrote:
> On 04/04/2008 07:36, in article wvbry77uxh19.fsf@astra06.norway.sun.com,
> "Ole-Hjalmar Kristensen"
> <ole-hjalmar.kristensen@substitute_employer_here.com> wrote:
> 
> > Interesting. I had not thought of Ada.Synchronous_Task_Control.  Apart
> > from that, I agree that a "best effort" implementation of standard
> > library like the membar_ops and atomic_ops which are part of the
> > Solaris C library would likely be sufficient.
> 
> Is there online documentation/code for that library?

docs.sun.com has sometimes been a good starting point.
http://docs.sun.com/app/docs/doc/819-2256/membar-ops-9f?a=view





^ permalink raw reply	[relevance 0%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-04-04  6:36  6%                               ` Ole-Hjalmar Kristensen
@ 2008-04-04 13:56  0%                                 ` (see below)
  2008-04-04 17:36  0%                                   ` Georg Bauhaus
  0 siblings, 1 reply; 33+ results
From: (see below) @ 2008-04-04 13:56 UTC (permalink / raw)


On 04/04/2008 07:36, in article wvbry77uxh19.fsf@astra06.norway.sun.com,
"Ole-Hjalmar Kristensen"
<ole-hjalmar.kristensen@substitute_employer_here.com> wrote:

> Interesting. I had not thought of Ada.Synchronous_Task_Control.  Apart
> from that, I agree that a "best effort" implementation of standard
> library like the membar_ops and atomic_ops which are part of the
> Solaris C library would likely be sufficient.

Is there online documentation/code for that library?

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[relevance 0%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  2008-04-02 14:59  4%                             ` (see below)
@ 2008-04-04  6:36  6%                               ` Ole-Hjalmar Kristensen
  2008-04-04 13:56  0%                                 ` (see below)
  2008-04-15 12:05  5%                               ` Ole-Hjalmar Kristensen
  1 sibling, 1 reply; 33+ results
From: Ole-Hjalmar Kristensen @ 2008-04-04  6:36 UTC (permalink / raw)


Interesting. I had not thought of Ada.Synchronous_Task_Control.  Apart
from that, I agree that a "best effort" implementation of standard
library like the membar_ops and atomic_ops which are part of the
Solaris C library would likely be sufficient. 


>>>>> "(b" == (see below) <yaldnif.w@blueyonder.co.uk> writes:

    (b> On 02/04/2008 08:22, in article wvbr4pakzpo1.fsf@astra06.norway.sun.com,
    (b> "Ole-Hjalmar Kristensen"
    (b> <ole-hjalmar.kristensen@substitute_employer_here.com> wrote:

    >> Yes, I know. So pragma atomic does not help very much by itself in
    >> implementing lock-free algorithms.

    (b> Yes, it's only one essential aspect.
 
    >>>> Agreed, but you may able to cheat and pack a pair of integers into
    >>>> a 64-bit atomic, and a compare-and-swap is also much cheaper than a
    >>>> protected object it seems.
    >> 
    >> (b> Yes, but this is completely implementation-dependent.
    >> (b> Not much above the semantic level of assembly.
    >> (b> I would take a lot of convincing that the performance
    >> (b> improvement was actually necessary.
    >> 
    >> I agree that it rarely should be necessary. It would have been nice to
    >> have a way of implementing lock-free algorithms in Ada efficiently,
    >> but entryless protected objects seems to be the best solution if
    >> you want a portable program.

    (b> It would not take too much - perhaps just a standard library including
    (b> read-barrier and write-barrier operations, and a selection of things like
    (b> CAS, TAS, EXCH, etc; mapped to m/c codes where these are provided,
    (b> and implemented using the architecture's native sync operations where not.

    (b> Is this the basis for an AI?

    (b> Following on my second post to the point, I was reminded of the package
    (b> Ada.Synchronous_Task_Control, which must also impose memory barriers is it
    (b> is to work reliably on a multiprocessor; so I tried that in my Simpson's
    (b> algorithm test as well. Here is the code:

    >> with Ada.Synchronous_Task_Control;
    >> package body Wait_Free_Atomicity is
    >> 
    >> procedure Sync is
    >> use Ada.Synchronous_Task_Control;
    >> Sema : Suspension_Object;
    >> Bool : Boolean := Current_State(Sema); -- either this
    >> begin
    >> -- Set_True(Sema);                     -- or
    >> -- Suspend_Until_True(Sema);           -- this
    >> end Sync;
    >> 
    >> procedure Update (Atomic_Item : in out an_Atomic; Item : in  an_Item) is
    >> Row : constant a_Bistate := not Atomic_Item.Last_Row_Inspected;
    >> Col : constant a_Bistate := not Atomic_Item.Last_Column_Updated(Row);
    >> begin
    >> Atomic_Item.Data_Slot_Matrix(Row, Col) := Item;
    >> Atomic_Item.Last_Column_Updated(Row) := Col;
    >> Atomic_Item.Last_Row_Updated := Row;
    >> Sync;
    >> end Update;
    >> 
    >> procedure Inspect (Atomic_Item : in out an_Atomic; Item : out an_Item) is
    >> Row : constant a_Bistate := Atomic_Item.Last_Row_Updated;
    >> Col : a_Bistate;
    >> pragma Atomic (Col);
    >> begin
    >> Atomic_Item.Last_Row_Inspected := Row;
    >> Col  := Atomic_Item.Last_Column_Updated(Row);
    >> Item := Atomic_Item.Data_Slot_Matrix(Row, Col);
    >> Sync;
    >> end Inspect;
    >> 
    >> end Wait_Free_Atomicity;

    (b> It works nicely, and is an order of magnitude faster than a protected
    (b> object:

    (b> 20_000_000 updates

    (b> with Suspend_Until_True sync:
    (b> No consistency failures.
    (b>         7.30 real        14.14 user         0.04 sys

    (b> with Current_State sync:
    (b> No consistency failures.
    (b>         3.57 real         6.97 user         0.02 sys

    (b> -- 
    (b> Bill Findlay
    (b> <surname><forename> chez blueyonder.co.uk

-- 
   C++: The power, elegance and simplicity of a hand grenade.



^ permalink raw reply	[relevance 6%]

* Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
  @ 2008-04-02 14:59  4%                             ` (see below)
  2008-04-04  6:36  6%                               ` Ole-Hjalmar Kristensen
  2008-04-15 12:05  5%                               ` Ole-Hjalmar Kristensen
  0 siblings, 2 replies; 33+ results
From: (see below) @ 2008-04-02 14:59 UTC (permalink / raw)


On 02/04/2008 08:22, in article wvbr4pakzpo1.fsf@astra06.norway.sun.com,
"Ole-Hjalmar Kristensen"
<ole-hjalmar.kristensen@substitute_employer_here.com> wrote:

> Yes, I know. So pragma atomic does not help very much by itself in
> implementing lock-free algorithms.

Yes, it's only one essential aspect.
 
>>> Agreed, but you may able to cheat and pack a pair of integers into
>>> a 64-bit atomic, and a compare-and-swap is also much cheaper than a
>>> protected object it seems.
> 
>     (b> Yes, but this is completely implementation-dependent.
>     (b> Not much above the semantic level of assembly.
>     (b> I would take a lot of convincing that the performance
>     (b> improvement was actually necessary.
> 
> I agree that it rarely should be necessary. It would have been nice to
> have a way of implementing lock-free algorithms in Ada efficiently,
> but entryless protected objects seems to be the best solution if
> you want a portable program.

It would not take too much - perhaps just a standard library including
read-barrier and write-barrier operations, and a selection of things like
CAS, TAS, EXCH, etc; mapped to m/c codes where these are provided,
and implemented using the architecture's native sync operations where not.

Is this the basis for an AI?

Following on my second post to the point, I was reminded of the package
Ada.Synchronous_Task_Control, which must also impose memory barriers is it
is to work reliably on a multiprocessor; so I tried that in my Simpson's
algorithm test as well. Here is the code:

> with Ada.Synchronous_Task_Control;
> package body Wait_Free_Atomicity is
>     
>        procedure Sync is
>           use Ada.Synchronous_Task_Control;
>           Sema : Suspension_Object;
>           Bool : Boolean := Current_State(Sema); -- either this
>        begin
>            -- Set_True(Sema);                     -- or
>            -- Suspend_Until_True(Sema);           -- this
>        end Sync;
>     
>     procedure Update (Atomic_Item : in out an_Atomic; Item : in  an_Item) is
>         Row : constant a_Bistate := not Atomic_Item.Last_Row_Inspected;
>         Col : constant a_Bistate := not Atomic_Item.Last_Column_Updated(Row);
>     begin
>         Atomic_Item.Data_Slot_Matrix(Row, Col) := Item;
>         Atomic_Item.Last_Column_Updated(Row) := Col;
>         Atomic_Item.Last_Row_Updated := Row;
>         Sync;
>     end Update;
>     
>     procedure Inspect (Atomic_Item : in out an_Atomic; Item : out an_Item) is
>         Row : constant a_Bistate := Atomic_Item.Last_Row_Updated;
>         Col : a_Bistate;
>         pragma Atomic (Col);
>     begin
>         Atomic_Item.Last_Row_Inspected := Row;
>         Col  := Atomic_Item.Last_Column_Updated(Row);
>         Item := Atomic_Item.Data_Slot_Matrix(Row, Col);
>         Sync;
>     end Inspect;
> 
> end Wait_Free_Atomicity;

It works nicely, and is an order of magnitude faster than a protected
object:

20_000_000 updates

with Suspend_Until_True sync:
No consistency failures.
        7.30 real        14.14 user         0.04 sys

with Current_State sync:
No consistency failures.
        3.57 real         6.97 user         0.02 sys

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[relevance 4%]

* Re: Ravenscar - program termination
  @ 2007-01-31  9:59  6%         ` Ludovic Brenta
  0 siblings, 0 replies; 33+ results
From: Ludovic Brenta @ 2007-01-31  9:59 UTC (permalink / raw)


Maciej Sobczak writes:
> I wrote a Hello World program and I want to impress my boss telling
> him that my program complies with Ravenscar recommendations. That
> sounds much more serious than a plain dumb Hello World program!

A high-integrity "hello world"?  With tasking? :)

+pragma Profile (Ravenscar);
 with Ada.Text_IO;
+with Ada.Synchronous_Task_Control;
 procedure Hello is
+   Blocker : Ada.Synchronous_Task_Control.Suspension_Object;
 begin
    Ada.Text_IO.Put_Line("Hello Ravenscar!");
    loop
-      null;
+      Ada.Synchronous_Task_Control.Suspend_Until_True (Blocker);
    end loop;
 end Hello;

That should solve your CPU utilisation problem :)

> OK, back to serious mode.
> One of the Ravenscar objectives is to allow implementations to provide
> stripped-down runtime when the profile is requested. This is a nice
> feature, even for programs that are not safety-critical in nature.
> How does GNAT handle this? Can I expect it to build smaller (faster?)
> executables when I say pragma Profile(Ravenscar) provided that the
> program complies to all the restrictions anyway?

I'm not sure how GNAT handles this, and I think it depends on the
target.  It makes no sense at all to write high-integrity software
running on a low-integrity operating system (not to mention
low-integrity hardware); the intention is that the high-integrity
Ravenscar run-time kernel *is* the operating system.

As a consequence, Ada.Text_IO in a high-integrity system makes little
sense, unless you have a high-integrity console driver.  Since the
console driver would be hardware-dependent, you'd have to write your
own to complement GNAT's minimal Ravenscar tasking kernel.

I think that's why, in effect, high-integrity implies embedded.

In low-integrity, non-embedded software, you cannot benefit from the
"minimal kernel", "lock-free operation" or "configurable scheduling
policies", but you can benefit from other inherent properties of the
tasking model, which reduce the opportunities for deadlocks.

PS. Keep in mind that calls to Ada.Text_IO.Put_Line are "potentially
blocking", so you cannot call them from a protected object in
Ravenscar.  See ARM 9.5.1(8, 10), D.13.1(4/2), H.5(5/2).

-- 
Ludovic Brenta.



^ permalink raw reply	[relevance 6%]

* Re: Problem with -gnatt
  @ 2004-10-24  5:45  4%                                     ` Jeffrey Carter
  0 siblings, 0 replies; 33+ results
From: Jeffrey Carter @ 2004-10-24  5:45 UTC (permalink / raw)


Brian May wrote:
> 
> However, as I think I might have said before, I have read that
> creating a semaphore using a protected type is inefficient, because
> protected types where intended to be much more flexible then
> semaphores.

There are places where semaphores are required. One is when exclusive 
control of external resources is required, and different combinations of 
such resources are required in different circumstances. Special 
attention to the order of obtaining and releasing such resources is 
needed to avoid deadlock.

There are three ways to deal with mutual exclusion: semaphores, 
protected objects, and passive tasks. Semaphores should be avoided when 
possible. Passive tasks, the main idiom in Ada 83, have the advantages 
of protected objects without the disadvantages. Potentially blocking 
operations may be made from critical regions in passive tasks, for 
example. The disadvantage of passive tasks is that they are tasks, and 
each operation requires a context switch.

There are places where each approach is preferable.

Note that compilers implementing Annex D provide the package 
Ada.Synchronous_Task_Control, which defines type Suspension_Object, 
which is essentially a binary semaphore (D.10), probably implemented 
more efficiently than using a protected object.

-- 
Jeff Carter
"You've got the brain of a four-year-old boy,
and I bet he was glad to get rid of it."
Horse Feathers
47




^ permalink raw reply	[relevance 4%]

* Re: Suspension_Object problem
  2003-01-15 15:35  5% Suspension_Object problem Philippe Laval
  2003-01-15 15:46  0% ` Jean-Pierre Rosen
@ 2003-01-15 19:02  0% ` Jeffrey Carter
  1 sibling, 0 replies; 33+ results
From: Jeffrey Carter @ 2003-01-15 19:02 UTC (permalink / raw)


Philippe Laval wrote:
> The following program compiles without error in gnat 3.14p.
> However the line "From H: P is now released" never shows up. What is
> wrong?
> 
> -- File Susp_O.adb
> with P_Pkg;
> with H_Pkg;
> procedure Susp_O is
> begin
>    null;
> end Susp_O;
> ----------------------------------------------------------------------------------------------
> 
> -- File P_Pkg.ads
> with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
> package P_Pkg is
>    protected type Protected_Lock is
>       procedure Set_Lock;
>       procedure Release;
>    private
>       Lock : Suspension_Object;
>    end Protected_Lock;
> 
>    type Lock_Access is access Protected_Lock;
>    Attack_Lock : Lock_Access;
> 
>    task P;
> 
> end P_Pkg;
> 
> ------------------------------------------------------------------------------------------------
> 
> -- File P_Pkg.ads
> package H_Pkg is
>    task H;
> end H_Pkg;
> ------------------------------------------------------------------------------------------------
> 
> -- File P_Pkg.adb
> with Ada.Text_IO; use Ada.Text_IO;
> package body P_Pkg is
>    protected body Protected_Lock is
>       procedure Set_Lock is
>       begin
>          Suspend_Until_True (Lock);
>       end Set_Lock;
> 
>       procedure Release is
>       begin
>          Set_True (Lock);
>       end Release;
>    end Protected_Lock;
> 
>    task body P is
>    begin
>       Attack_Lock := new Protected_Lock;
>       Put_Line ("P is being suspended.");
>       Put_Line ("Waiting to be released by H...");
>       Attack_Lock.Set_Lock;
> 
>       Put_Line ("P is now released.");
>    end P;
> end P_Pkg;
> ------------------------------------------------------------------------------------------------
> 
> -- File H_Pkg.adb
> with Ada.Text_IO; use Ada.Text_IO;
> with P_Pkg;
> package body H_Pkg is
>    task body H is
>    begin
>       delay 1.0;
>       P_Pkg.Attack_Lock.Release;
>       Put_Line ("From H : P is released now!");
>    end H;
> end H_Pkg;

This seems entirely inappropriate. Either your 2 tasks should operate on 
a shared Suspension_Object or they should operate on a shared protected 
object. Mixing the 2 seems inappropriate, especially as some operations 
on Suspension_Objects are intended to be blocking operations, and 
therefore illegal to call from a protected object.

I suspect that your problem comes because the call to Suspend_Until_True 
blocks P before it completes executing Set_Lock, so it never frees the 
protected object to allow H to execute Release.

There is also no need to use access types in this example.

-- 
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life




^ permalink raw reply	[relevance 0%]

* Re: Suspension_Object problem
  2003-01-15 15:35  5% Suspension_Object problem Philippe Laval
@ 2003-01-15 15:46  0% ` Jean-Pierre Rosen
  2003-01-15 19:02  0% ` Jeffrey Carter
  1 sibling, 0 replies; 33+ results
From: Jean-Pierre Rosen @ 2003-01-15 15:46 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1607 bytes --]


"Philippe Laval" <laval@obs-vlfr.fr> a �crit dans le message de news: 3E257FD5.8765352C@obs-vlfr.fr...
> The following program compiles without error in gnat 3.14p.
> However the line "From H: P is now released" never shows up. What is
> wrong?
>
> -- File Susp_O.adb
> with P_Pkg;
> with H_Pkg;
> procedure Susp_O is
> begin
>    null;
> end Susp_O;
> ----------------------------------------------------------------------------------------------
>
> -- File P_Pkg.ads
> with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
> package P_Pkg is
>    protected type Protected_Lock is
>       procedure Set_Lock;
>       procedure Release;
>    private
>       Lock : Suspension_Object;
>    end Protected_Lock;
>
>    type Lock_Access is access Protected_Lock;
>    Attack_Lock : Lock_Access;
>
>    task P;
>
> end P_Pkg;
>
> ------------------------------------------------------------------------------------------------
>
> -- File P_Pkg.ads
> package H_Pkg is
>    task H;
> end H_Pkg;
> ------------------------------------------------------------------------------------------------
>
> -- File P_Pkg.adb
> with Ada.Text_IO; use Ada.Text_IO;
> package body P_Pkg is
>    protected body Protected_Lock is
>       procedure Set_Lock is
>       begin
>          Suspend_Until_True (Lock);
>       end Set_Lock;
>
Suspend_Until_True is a potentially blocking operation, and therefore not allowed in a protected procedure.
(D.10(10))

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[relevance 0%]

* Suspension_Object problem
@ 2003-01-15 15:35  5% Philippe Laval
  2003-01-15 15:46  0% ` Jean-Pierre Rosen
  2003-01-15 19:02  0% ` Jeffrey Carter
  0 siblings, 2 replies; 33+ results
From: Philippe Laval @ 2003-01-15 15:35 UTC (permalink / raw)


The following program compiles without error in gnat 3.14p.
However the line "From H: P is now released" never shows up. What is
wrong?

-- File Susp_O.adb
with P_Pkg;
with H_Pkg;
procedure Susp_O is
begin
   null;
end Susp_O;
----------------------------------------------------------------------------------------------

-- File P_Pkg.ads
with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
package P_Pkg is
   protected type Protected_Lock is
      procedure Set_Lock;
      procedure Release;
   private
      Lock : Suspension_Object;
   end Protected_Lock;

   type Lock_Access is access Protected_Lock;
   Attack_Lock : Lock_Access;

   task P;

end P_Pkg;

------------------------------------------------------------------------------------------------

-- File P_Pkg.ads
package H_Pkg is
   task H;
end H_Pkg;
------------------------------------------------------------------------------------------------

-- File P_Pkg.adb
with Ada.Text_IO; use Ada.Text_IO;
package body P_Pkg is
   protected body Protected_Lock is
      procedure Set_Lock is
      begin
         Suspend_Until_True (Lock);
      end Set_Lock;

      procedure Release is
      begin
         Set_True (Lock);
      end Release;
   end Protected_Lock;

   task body P is
   begin
      Attack_Lock := new Protected_Lock;
      Put_Line ("P is being suspended.");
      Put_Line ("Waiting to be released by H...");
      Attack_Lock.Set_Lock;

      Put_Line ("P is now released.");
   end P;
end P_Pkg;
------------------------------------------------------------------------------------------------

-- File H_Pkg.adb
with Ada.Text_IO; use Ada.Text_IO;
with P_Pkg;
package body H_Pkg is
   task body H is
   begin
      delay 1.0;
      P_Pkg.Attack_Lock.Release;
      Put_Line ("From H : P is released now!");
   end H;
end H_Pkg;
------------------------------------------------------------------------------------------------

Philippe Laval
Observatoire Oc�anologique
F-06234 Villefranche-sur-Mer CEDEX
laval@obs-vlfr.fr




^ permalink raw reply	[relevance 5%]

* Re: Semaphores without using entry
  2001-12-27  9:53  5% Semaphores without using entry Jos� Alberto
  2001-12-27 10:09  0% ` Michal Nowak
  2001-12-28 15:03  0% ` Matthew Heaney
@ 2001-12-28 15:10  0% ` Matthew Heaney
  2 siblings, 0 replies; 33+ results
From: Matthew Heaney @ 2001-12-28 15:10 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]


"Jos� Alberto" <HIGHLAND@santandersupernet.com> wrote in message
news:a0eqqq$9dk$1@news.ya.com...
> Hello to everybody,
>
> I need to use semaphores for a concurrent program, but I've been told not
to
> use the entry clause, but I can use the Ada.Synchronous_Task_Control
> package.

Actually, when I searched for "suspension" using the search engine, these 5
articles came up:

      Item # Date Time Recs   Subject
      000143 99/04/11 01:35 226  Task Synchronization Using Suspension
Objects
      000155 99/04/19 04:54 427  I'm Queueless, or, Suspension Objects
Instead of Entries
      000159 99/05/05 01:26 727  Do Not Entry: Bounded Queue of Suspension
Objects
      000173 99/10/24 17:19 380  Bounded Buffer with Entry-less Get Queue
      000175 99/10/27 00:05 412  Bounded Buffer with Entry-less Get Queue -
Update


See http://www.acm.org/archives/patterns.html for the complete list.

I did a whole series of articles about concurrency patterns in Ada95.  Maybe
they will be of some use to you.







^ permalink raw reply	[relevance 0%]

* Re: Semaphores without using entry
  2001-12-27  9:53  5% Semaphores without using entry Jos� Alberto
  2001-12-27 10:09  0% ` Michal Nowak
@ 2001-12-28 15:03  0% ` Matthew Heaney
  2001-12-28 15:10  0% ` Matthew Heaney
  2 siblings, 0 replies; 33+ results
From: Matthew Heaney @ 2001-12-28 15:03 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 628 bytes --]


"Jos� Alberto" <HIGHLAND@santandersupernet.com> wrote in message
news:a0eqqq$9dk$1@news.ya.com...
> Hello to everybody,
>
> I need to use semaphores for a concurrent program, but I've been told not
to
> use the entry clause, but I can use the Ada.Synchronous_Task_Control
> package.

You may want to take a look at my article in the patterns archive, on this
very subject:

I'm Queueless, or, Suspension Objects Instead of Entries
http://www.acm.org/archives/wa.cgi?A2=ind9904&L=patterns&P=R7659

See also:

Task Synchronization Using Suspension Objects
http://www.acm.org/archives/wa.cgi?A2=ind9904&L=patterns&P=R4138







^ permalink raw reply	[relevance 0%]

* Re: Semaphores without using entry
  2001-12-27 10:09  0% ` Michal Nowak
@ 2001-12-27 23:24  0%   ` Jos� Alberto
  0 siblings, 0 replies; 33+ results
From: Jos� Alberto @ 2001-12-27 23:24 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1016 bytes --]

Thanks for your help

Jos� Alberto Adrados Sanz
"Michal Nowak" <vinnie@inetia.pl> escribi� en el mensaje
news:mailman.1009447502.24237.comp.lang.ada@ada.eu.org...
On 01-12-27 at 10:53 Jos� Alberto wrote:

>Hello to everybody,
>
>I need to use semaphores for a concurrent program, but I've been told not
>to
>use the entry clause, but I can use the Ada.Synchronous_Task_Control
>package.
>
>Can anybody help me?
>
>Thanks in advance
>
>Jos� Alberto

Try to read in Reference Manual, Annex D, Section D.10.
You should find enough info to give you idea how to
solve you problem there.

http://www.adapower.com/rm95/index.html
http://www.adapower.com/rm95/arm95_296.html#SEC296

Good luck,
Mike
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__






^ permalink raw reply	[relevance 0%]

* Re: Semaphores without using entry
  2001-12-27  9:53  5% Semaphores without using entry Jos� Alberto
@ 2001-12-27 10:09  0% ` Michal Nowak
  2001-12-27 23:24  0%   ` Jos� Alberto
  2001-12-28 15:03  0% ` Matthew Heaney
  2001-12-28 15:10  0% ` Matthew Heaney
  2 siblings, 1 reply; 33+ results
From: Michal Nowak @ 2001-12-27 10:09 UTC (permalink / raw)
  To: comp.lang.ada usegroup->mailing list gateway

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 878 bytes --]

On 01-12-27 at 10:53 José Alberto wrote:

>Hello to everybody,
>
>I need to use semaphores for a concurrent program, but I've been told not
>to
>use the entry clause, but I can use the Ada.Synchronous_Task_Control
>package.
>
>Can anybody help me?
>
>Thanks in advance
>
>José Alberto

Try to read in Reference Manual, Annex D, Section D.10.
You should find enough info to give you idea how to
solve you problem there.

http://www.adapower.com/rm95/index.html
http://www.adapower.com/rm95/arm95_296.html#SEC296

Good luck,
Mike
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




^ permalink raw reply	[relevance 0%]

* Semaphores without using entry
@ 2001-12-27  9:53  5% Jos� Alberto
  2001-12-27 10:09  0% ` Michal Nowak
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ results
From: Jos� Alberto @ 2001-12-27  9:53 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

Hello to everybody,

I need to use semaphores for a concurrent program, but I've been told not to
use the entry clause, but I can use the Ada.Synchronous_Task_Control
package.

Can anybody help me?

Thanks in advance

Jos� Alberto







^ permalink raw reply	[relevance 5%]

* Re: Elaboration checks
  @ 2000-02-14  0:00  3% ` Matthew Heaney
  0 siblings, 0 replies; 33+ results
From: Matthew Heaney @ 2000-02-14  0:00 UTC (permalink / raw)


In article <38A6BB10.560D973A@dowie-cs.demon.co.uk> , Martin Dowie 
<martin@dowie-cs.demon.co.uk>  wrote:

> we plan to ensure that each of our packages provides an 'Initialise'
> routine to assign package-local initial values. all our tasks currently
> block on an 'accept Initialise' already.
>
> anything else we can do?

Here's an idea.  Each tack entry consumes run-time resources.  An
Initialize task entry is called only once, yet continues to consume
resources for the duration of the program.

If you're using Ada95, you can get rid of the Initialize entry by using
a Suspension_Object.  This may or may not reduce storage costs (it
depends on how SOs are implemented).

So instead of

package body P is

  task TO is
    entry Init;
    entry E;
  end TO;

  procedure Init is
  begin
    TO.Init;
  end;
...

  task body TO is
  begin
    accept Initialize;
    ...
  end TO;

end P;

You can replace the task entry with a suspension object:

with Ada.Synchronous_Task_Control;  use Ada.STC;
package body P is

  task TO is
    entry E;  -- note no Init entry
  end TO;

  Initialization : Suspension_Object;

  procedure Init is
  begin
    Set_True (Initialization);
  end Init;
...
  task body TO is
  begin
    Suspend_Until_True (Initialization);
  end TO;

end P;


You can also use a protected object, that is shared by all the tasks in
the system:

package Task_Initialization is

  protected Signal is

    entry Wait;

    procedure Send;

  private

    Initialized : Boolean := False;

  end Signal;

end Task_Initialization;


Now instead of every task having its own initialize entry, it simply
waits on the global task initialization signal object:

with Task_Initialization;
package body P is
...
  task body TO is
  begin
    Task_Initialization.Signal.Wait;
    ...
  end TO;

end P;

Now during startup, you only have to call one task initialization signal
object, instead of every task separately.  It's basically a way of
implementing a broadcast in Ada95.

These days, explicit Initialize entries for tasks are rarely necessary.
You can eliminate (all!) task entries by using protected objects, and
you can eliminate protected object entry queues by using suspension
objects.


--
The purpose of the system is what it does.

Stafford Beer





^ permalink raw reply	[relevance 3%]

* Re: Ada83 and Ada95 interrupt handling
  @ 1999-03-05  0:00  3% ` Robert A Duff
  0 siblings, 0 replies; 33+ results
From: Robert A Duff @ 1999-03-05  0:00 UTC (permalink / raw)


Armin <ArminSchmidle@swol.de> writes:

> I am porting an Ada83 application to Ada95. In Ada83 there was a
> construction
> known as interrupt entry.
...
> How can I do the same thing in Ada95 ?

I just happened to be working on some examples of interrupt handling for
our (Averstar's) AdaMagic for SHARC implementation, which we validated
last month.

When using a protected procedure as an interrupt handler, there are (at
least) two ways to make the handler notify a task that the interrupt has
occurred.  You can have the task wait on an entry of the same protected
object as the interrupt handler.  Or, you can use suspension objects.

Here's an extract from the documentation I wrote:

...
Example 2.

The second example prints the following:

 Hello from Interrupt_Test_With_Entries main procedure.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Waiting_Task: Got interrupt.
 Generating interrupt.
 Goodbye from Interrupt_Test_With_Entries main procedure.
 Waiting_Task: Got interrupt.
 Goodbye from Waiting_Task.

----------------------------------------------------------------

-- This example illustrates how an interrupt handler (a protected
-- procedure) may communicate with a task using an entry.  The interrupt
-- handler is called when the interrupt occurs, and it causes the
-- entry's barrier to become True.  The task waits by calling the entry;
-- it is blocked until the barrier becomes True.

-- In this example, we simulate 10 interrupts, and we have a task
-- (Waiting_Task) that waits for 10 interrupts by calling the entry.
-- Each interrupt triggers one call to the entry to proceed.  In this
-- example, the only information being transmitted back to the waiting
-- task is the fact that the interrupt has occurred.

-- In a real program, the protected object might have additional
-- operations to do something to some external device (e.g. initiate
-- some I/O).  This might cause the device to generate an interrupt.
-- The interrupt would not be noticed until after this operation
-- returns, even if the device generates the interrupt right away;
-- that's because of the priority rules.  Also, the interrupt handler
-- might get some information from the device, save it locally in the
-- protected object, and then the entry body might pass this information
-- back to the task via an 'out' parameter.

-- In other words, a protected object used in this way acts as a "device
-- driver", containing operations to initiate I/O operations, to wait
-- for operations to complete, and to handle interrupts.  Anything that
-- needs to be done while masking the interrupt of the device should be
-- part of the protected object.

-- Note that if multiple device drivers are needed for similar devices,
-- it is convenient to declare a protected type, and declare multiple
-- objects of that type.  Discriminants can be used to pass in
-- information specific to individual devices.

----------------------------------------------------------------

with Ada.Interrupts.Names; use Ada.Interrupts.Names;
with System.RTS.Temp_IO; use System.RTS.Temp_IO;

package Interrupt_Test_With_Entries is

    -- Empty.

end Interrupt_Test_With_Entries;

----------------------------------------------------------------

package Interrupt_Test_With_Entries.Handlers is

    pragma Elaborate_Body;

    protected Handler_PO is

        procedure Handler; -- The interrupt handler.
        pragma Attach_Handler(Handler, SFT0I);
            -- SFT0I is declared in Ada.Interrupts.Names.

        entry Await_Interrupt;
            -- Each time Handler is called,
            -- this entry is triggered.

    private

        Interrupt_Occurred: Boolean := False;

    end Handler_PO;

end Interrupt_Test_With_Entries.Handlers;

----------------------------------------------------------------

package body Interrupt_Test_With_Entries.Handlers is

    protected body Handler_PO is

        procedure Handler is
        begin
            Interrupt_Occurred := True;
        end Handler;

        entry Await_Interrupt when Interrupt_Occurred is
        begin
            Interrupt_Occurred := False;
        end Await_Interrupt;

    end Handler_PO;

end Interrupt_Test_With_Entries.Handlers;

----------------------------------------------------------------

package Interrupt_Test_With_Entries.Waiting_Tasks is

    pragma Elaborate_Body; -- So the body is allowed.

end Interrupt_Test_With_Entries.Waiting_Tasks;

----------------------------------------------------------------

with Interrupt_Test_With_Entries.Handlers; use Interrupt_Test_With_Entries.Handlers;
package body Interrupt_Test_With_Entries.Waiting_Tasks is

    task Waiting_Task;

    task body Waiting_Task is
    begin
        for I in 1..10 loop
            Handler_PO.Await_Interrupt;
            Put_Line("Waiting_Task: Got interrupt.");
        end loop;
        Put_Line("Goodbye from Waiting_Task.");
    end Waiting_Task;

end Interrupt_Test_With_Entries.Waiting_Tasks;

----------------------------------------------------------------

with System.Machine_Intrinsics;

with Interrupt_Test_With_Entries.Waiting_Tasks;
    -- There are no references to this package; this with_clause is here
    -- so that task Waiting_Task will be included in the program.

procedure Interrupt_Test_With_Entries.Main is

    procedure Generate_Interrupt(Interrupt : Ada.Interrupts.Interrupt_ID) is
        -- This uses machine code intrinsics to simulate a hardware
        -- interrupt, by generating an interrupt in software.

        use System.Machine_Intrinsics;

        -- This sets the N'th bit in IRPTL, where N is the interrupt number,
        -- which causes the interrupt to happen; see page 3-26 of the
        -- ADSP-2106x SHARC Users' Manual, Second Edition.
        -- We want to use the BIT SET instruction, so it's atomic,
        -- but that instruction requires an immediate value;
        -- we can't calculate 2**N and use that as the mask;
        -- hence the rather repetitive code below.

        procedure Gen_0 is
            pragma Inline(Gen_0);
        begin
            Asm("BIT SET IRPTL 0x00000001;");
        end Gen_0;

        procedure Gen_1 is
            pragma Inline(Gen_1);
        begin
            Asm("BIT SET IRPTL 0x00000002;");
        end Gen_1;

        procedure Gen_2 is
            pragma Inline(Gen_2);
        begin
            Asm("BIT SET IRPTL 0x00000004;");
        end Gen_2;

        procedure Gen_3 is
            pragma Inline(Gen_3);
        begin
            Asm("BIT SET IRPTL 0x00000008;");
        end Gen_3;

        procedure Gen_4 is
            pragma Inline(Gen_4);
        begin
            Asm("BIT SET IRPTL 0x00000010;");
        end Gen_4;

        procedure Gen_5 is
            pragma Inline(Gen_5);
        begin
            Asm("BIT SET IRPTL 0x00000020;");
        end Gen_5;

        procedure Gen_6 is
            pragma Inline(Gen_6);
        begin
            Asm("BIT SET IRPTL 0x00000040;");
        end Gen_6;

        procedure Gen_7 is
            pragma Inline(Gen_7);
        begin
            Asm("BIT SET IRPTL 0x00000080;");
        end Gen_7;

        procedure Gen_8 is
            pragma Inline(Gen_8);
        begin
            Asm("BIT SET IRPTL 0x00000100;");
        end Gen_8;

        procedure Gen_9 is
            pragma Inline(Gen_9);
        begin
            Asm("BIT SET IRPTL 0x00000200;");
        end Gen_9;

        procedure Gen_10 is
            pragma Inline(Gen_10);
        begin
            Asm("BIT SET IRPTL 0x00000400;");
        end Gen_10;

        procedure Gen_11 is
            pragma Inline(Gen_11);
        begin
            Asm("BIT SET IRPTL 0x00000800;");
        end Gen_11;

        procedure Gen_12 is
            pragma Inline(Gen_12);
        begin
            Asm("BIT SET IRPTL 0x00001000;");
        end Gen_12;

        procedure Gen_13 is
            pragma Inline(Gen_13);
        begin
            Asm("BIT SET IRPTL 0x00002000;");
        end Gen_13;

        procedure Gen_14 is
            pragma Inline(Gen_14);
        begin
            Asm("BIT SET IRPTL 0x00004000;");
        end Gen_14;

        procedure Gen_15 is
            pragma Inline(Gen_15);
        begin
            Asm("BIT SET IRPTL 0x00008000;");
        end Gen_15;

        procedure Gen_16 is
            pragma Inline(Gen_16);
        begin
            Asm("BIT SET IRPTL 0x00010000;");
        end Gen_16;

        procedure Gen_17 is
            pragma Inline(Gen_17);
        begin
            Asm("BIT SET IRPTL 0x00020000;");
        end Gen_17;

        procedure Gen_18 is
            pragma Inline(Gen_18);
        begin
            Asm("BIT SET IRPTL 0x00040000;");
        end Gen_18;

        procedure Gen_19 is
            pragma Inline(Gen_19);
        begin
            Asm("BIT SET IRPTL 0x00080000;");
        end Gen_19;

        procedure Gen_20 is
            pragma Inline(Gen_20);
        begin
            Asm("BIT SET IRPTL 0x00100000;");
        end Gen_20;

        procedure Gen_21 is
            pragma Inline(Gen_21);
        begin
            Asm("BIT SET IRPTL 0x00200000;");
        end Gen_21;

        procedure Gen_22 is
            pragma Inline(Gen_22);
        begin
            Asm("BIT SET IRPTL 0x00400000;");
        end Gen_22;

        procedure Gen_23 is
            pragma Inline(Gen_23);
        begin
            Asm("BIT SET IRPTL 0x00800000;");
        end Gen_23;

        procedure Gen_24 is
            pragma Inline(Gen_24);
        begin
            Asm("BIT SET IRPTL 0x01000000;");
        end Gen_24;

        procedure Gen_25 is
            pragma Inline(Gen_25);
        begin
            Asm("BIT SET IRPTL 0x02000000;");
        end Gen_25;

        procedure Gen_26 is
            pragma Inline(Gen_26);
        begin
            Asm("BIT SET IRPTL 0x04000000;");
        end Gen_26;

        procedure Gen_27 is
            pragma Inline(Gen_27);
        begin
            Asm("BIT SET IRPTL 0x08000000;");
        end Gen_27;

        procedure Gen_28 is
            pragma Inline(Gen_28);
        begin
            Asm("BIT SET IRPTL 0x10000000;");
        end Gen_28;

        procedure Gen_29 is
            pragma Inline(Gen_29);
        begin
            Asm("BIT SET IRPTL 0x20000000;");
        end Gen_29;

        procedure Gen_30 is
            pragma Inline(Gen_30);
        begin
            Asm("BIT SET IRPTL 0x40000000;");
        end Gen_30;

        procedure Gen_31 is
            pragma Inline(Gen_31);
        begin
            Asm("BIT SET IRPTL 0x80000000;");
        end Gen_31;

        subtype Handleable_Range is Ada.Interrupts.Interrupt_ID
          range 0..31; -- These are the only interrupts that
                       -- actually exist in the hardware.
    begin
        case Handleable_Range'(Interrupt) is
            when 0 => Gen_0;
            when 1 => Gen_1;
            when 2 => Gen_2;
            when 3 => Gen_3;
            when 4 => Gen_4;
            when 5 => Gen_5;
            when 6 => Gen_6;
            when 7 => Gen_7;
            when 8 => Gen_8;
            when 9 => Gen_9;
            when 10 => Gen_10;
            when 11 => Gen_11;
            when 12 => Gen_12;
            when 13 => Gen_13;
            when 14 => Gen_14;
            when 15 => Gen_15;
            when 16 => Gen_16;
            when 17 => Gen_17;
            when 18 => Gen_18;
            when 19 => Gen_19;
            when 20 => Gen_20;
            when 21 => Gen_21;
            when 22 => Gen_22;
            when 23 => Gen_23;
            when 24 => Gen_24;
            when 25 => Gen_25;
            when 26 => Gen_26;
            when 27 => Gen_27;
            when 28 => Gen_28;
            when 29 => Gen_29;
            when 30 => Gen_30;
            when 31 => Gen_31;
        end case;
    end Generate_Interrupt;

begin

    -- Generate 10 simulated interrupts, with delays in between.

    Put_Line("Hello from Interrupt_Test_With_Entries main procedure.");
    for I in 1..10 loop
        delay 0.01;
        Put_Line("Generating interrupt.");
        Generate_Interrupt(SFT0I);
    end loop;
    Put_Line("Goodbye from Interrupt_Test_With_Entries main procedure.");

end Interrupt_Test_With_Entries.Main;

================================================================
================================================================

Example 3.

The third example prints the following:

 Hello from Suspension_Objects_Test main procedure. 
 Generating interrupt. 
 Waiting_Task: Got interrupt. 
 Generating interrupt. 
 Waiting_Task: Got interrupt. 
 Generating interrupt. 
 Waiting_Task: Got interrupt. 
 Generating interrupt. 
 Waiting_Task: Got interrupt. 
 Goodbye from Waiting_Task. 
 Generating interrupt. 
 Generating interrupt. 
 Generating interrupt. 
 Generating interrupt. 
 Generating interrupt. 
 Generating interrupt. 
 Goodbye from Suspension_Objects_Test main procedure. 

-- This example illustrates how an interrupt handler
-- (a protected procedure) may communicate with a task
-- using a suspension object.  A suspension object allows a
-- task or interrupt handler to notify another task that some
-- event (in our case, an interrupt) has occurred.
-- Each time the interrupt occurs, the suspension object is set to True.
-- The task waits for this event by calling Suspend_Until_True.

-- In this example, we simulate some interrupts,
-- and we have a task (Waiting_Task) that waits for them
-- using a suspension object called Interrupt_Occurred.

-- Note that if the task is already waiting (the usual case) when the
-- interrupt occurs, Interrupt_Occurred is only set to True momentarily;
-- Suspend_Until_True automatically resets it to False.  If the task is
-- not waiting, then the True state will be remembered, and when the
-- task gets around to waiting, it will reset it to False and proceed
-- immediately.

-- Note that only one task can wait on a given suspension object; it's
-- sort of like a protected object with an entry queue of length one,
-- which allows it to be implemented more efficiently.  This means that
-- the programmer using suspension objects has to know which task will
-- do the waiting; it's as if that task has a kind of ownership of that
-- particular suspension object.

----------------------------------------------------------------

with Ada.Interrupts.Names; use Ada.Interrupts.Names;
with System.RTS.Temp_IO; use System.RTS.Temp_IO;

package Suspension_Objects_Test is

    -- Empty.

end Suspension_Objects_Test;

----------------------------------------------------------------

with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
package Suspension_Objects_Test.Handlers is

    pragma Elaborate_Body;

    protected Handler_PO is

        procedure Handler; -- The interrupt handler.
        pragma Attach_Handler(Handler, SFT0I);

    end Handler_PO;

    Interrupt_Occurred: Suspension_Object;
        -- Default-initialized to False.
        -- Set to True for each interrupt.

end Suspension_Objects_Test.Handlers;

----------------------------------------------------------------

package body Suspension_Objects_Test.Handlers is

    protected body Handler_PO is

        procedure Handler is
        begin
            Set_True(Interrupt_Occurred);
        end Handler;

    end Handler_PO;

end Suspension_Objects_Test.Handlers;

----------------------------------------------------------------

package Suspension_Objects_Test.Waiting_Tasks is

    pragma Elaborate_Body; -- So the body is allowed.

end Suspension_Objects_Test.Waiting_Tasks;

----------------------------------------------------------------

with Suspension_Objects_Test.Handlers; use Suspension_Objects_Test.Handlers;
with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
package body Suspension_Objects_Test.Waiting_Tasks is

    task Waiting_Task;

    task body Waiting_Task is
    begin
        for I in 1..4 loop
            Suspend_Until_True(Interrupt_Occurred);
            Put_Line("Waiting_Task: Got interrupt.");
        end loop;
        Put_Line("Goodbye from Waiting_Task.");
    end Waiting_Task;

end Suspension_Objects_Test.Waiting_Tasks;

----------------------------------------------------------------

with System.Machine_Intrinsics;

with Suspension_Objects_Test.Waiting_Tasks;
    -- There are no references to this package; this with_clause is here
    -- so that task Waiting_Task will be included in the program.

procedure Suspension_Objects_Test.Main is

    procedure Generate_Interrupt(Interrupt : Ada.Interrupts.Interrupt_ID) is
        ... -- as in previous example
    end Generate_Interrupt;

begin

    -- Generate some simulated interrupts, with delays in between.

    Put_Line("Hello from Suspension_Objects_Test main procedure.");
    for I in 1..10 loop
        delay 0.01;
        Put_Line("Generating interrupt.");
        Generate_Interrupt(SFT0I);
    end loop;
    Put_Line("Goodbye from Suspension_Objects_Test main procedure.");

end Suspension_Objects_Test.Main;
-- 
Change robert to bob to get my real email address.  Sorry.




^ permalink raw reply	[relevance 3%]

Results 1-33 of 33 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
1999-02-23  0:00     Ada83 and Ada95 interrupt handling Armin
1999-03-05  0:00  3% ` Robert A Duff
2000-02-13  0:00     Elaboration checks Martin Dowie
2000-02-14  0:00  3% ` Matthew Heaney
2001-12-27  9:53  5% Semaphores without using entry Jos� Alberto
2001-12-27 10:09  0% ` Michal Nowak
2001-12-27 23:24  0%   ` Jos� Alberto
2001-12-28 15:03  0% ` Matthew Heaney
2001-12-28 15:10  0% ` Matthew Heaney
2003-01-15 15:35  5% Suspension_Object problem Philippe Laval
2003-01-15 15:46  0% ` Jean-Pierre Rosen
2003-01-15 19:02  0% ` Jeffrey Carter
2004-10-07 10:40     Javadoc-like for Ada Alex R. Mosteo
2004-10-07 11:46     ` stephane richard
2004-10-07 13:05       ` Marc A. Criley
2004-10-07 13:39         ` Alex R. Mosteo
2004-10-07 16:51           ` Problem with -gnatt (was Re: Javadoc-like for Ada) Alex R. Mosteo
2004-10-07 19:21             ` Problem with -gnatt Ludovic Brenta
2004-10-08  8:45               ` Alex R. Mosteo
2004-10-15 20:06                 ` Matthew Heaney
2004-10-18  7:59                   ` Alex R. Mosteo
2004-10-18 16:48                     ` Matthew Heaney
2004-10-18 18:21                       ` Alex R. Mosteo
2004-10-19  0:20                         ` Matthew Heaney
2004-10-19  2:41                           ` Brian May
2004-10-19  3:08                             ` Matthew Heaney
2004-10-19  7:15                               ` Alex R. Mosteo
2004-10-19 14:52                                 ` Matthew Heaney
2004-10-19 15:46                                   ` Alex R. Mosteo
2004-10-19 20:03                                     ` Matthew Heaney
2004-10-23  6:28                                       ` Brian May
2004-10-24  5:45  4%                                     ` Jeffrey Carter
2007-01-29 16:34     Ravenscar - program termination Maciej Sobczak
2007-01-29 19:53     ` Ludovic Brenta
2007-01-30  8:09       ` Maciej Sobczak
2007-01-30  9:37         ` Markus E Leypold
2007-01-31  9:01           ` Maciej Sobczak
2007-01-31  9:59  6%         ` Ludovic Brenta
2008-03-08  6:04     Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! ME
2008-03-08 22:11     ` Maciej Sobczak
2008-03-10 21:24       ` Randy Brukardt
2008-03-22 22:43         ` Florian Weimer
2008-03-26 13:49           ` Ole-Hjalmar Kristensen
2008-03-26 21:27             ` Florian Weimer
2008-03-27  9:31               ` Ole-Hjalmar Kristensen
2008-03-27 23:10                 ` Florian Weimer
2008-03-28  9:51                   ` Ole-Hjalmar Kristensen
2008-03-28 18:12                     ` Florian Weimer
2008-03-31  7:59                       ` Ole-Hjalmar Kristensen
2008-03-31 13:03                         ` (see below)
2008-04-01  9:02                           ` Ole-Hjalmar Kristensen
2008-04-01 14:12                             ` (see below)
2008-04-02  7:22                               ` Ole-Hjalmar Kristensen
2008-04-02 14:59  4%                             ` (see below)
2008-04-04  6:36  6%                               ` Ole-Hjalmar Kristensen
2008-04-04 13:56  0%                                 ` (see below)
2008-04-04 17:36  0%                                   ` Georg Bauhaus
2008-04-04 17:40  0%                                     ` (see below)
2008-04-15 12:05  5%                               ` Ole-Hjalmar Kristensen
2008-05-28 19:14     [Ravenscar] run tasks on events Sebastian Hanigk
2008-05-30  7:26  3% ` Niklas Holsti
2011-11-17 15:33     Freezing a task Rego, P.
2011-11-17 17:13  5% ` Adam Beneschan
2011-11-17 18:01  0%   ` AdaMagica
2011-11-18  1:22  0%   ` Rego, P.
2011-11-18  7:24     ` anon
2011-11-18 22:25       ` Anh Vo
2011-11-19  7:37  4%     ` anon
2014-09-25 13:44     can someone help me with this code (explanation) Stribor40
2014-09-25 14:56     ` Björn Lundin
2014-09-25 15:54       ` Stribor40
2014-09-25 17:11         ` Niklas Holsti
2014-09-25 19:41           ` Stribor40
2014-09-25 20:10             ` Niklas Holsti
2014-09-25 22:27               ` Jeffrey Carter
2014-09-26  7:04                 ` Björn Lundin
2014-09-26  7:58                   ` J-P. Rosen
2014-09-26 10:24  5%                 ` G.B.
2016-02-07 22:45  4% ANN: Cortex GNAT RTS 20160207 Simon Wright
2016-03-14 17:42  4% ANN: Cortex GNAT RTS 20160314 Simon Wright
2016-05-22 14:20  3% ANN: Cortex GNAT RTS 20160522 Simon Wright
2016-08-25  0:41     How to simulate semaphores with Ada's tasks? Andrew Shvets
2016-08-25  7:55  5% ` G.B.
2020-05-03 10:43     Ravenscar - release multiple tasks when an event occurs Simon Wright
2020-05-03 11:50  4% ` Niklas Holsti
2020-05-05 16:02  0%   ` Simon Wright
2020-05-05 16:16  0%     ` Niklas Holsti
2020-06-10 11:14     How to terminate all running tasks? Gilbert Gosseyn
2020-06-10 12:12  7% ` Niklas Holsti
2020-06-10 12:29  4%   ` Niklas Holsti

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