From: anon@att.net
Subject: Re: Interrupts handling in ADA
Date: Mon, 12 Dec 2011 03:19:26 +0000 (UTC)
Date: 2011-12-12T03:19:26+00:00 [thread overview]
Message-ID: <jc3rrs$27sq$1@news.ett.com.ua> (raw)
In-Reply-To: 30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24
-- Interrupts are not necessary. From you description a simple set of
-- tasks is all that is needed.
--
-- This program outline uses three task to read three sockets and
-- after pre-processing and verifing data (if needed) passes this
-- data to a main task. The main task then can continue processing
-- this data.
--
-- Exception handling is limited to Socket error which will cause
-- that task to die and after reporting to the Main task. Then Main
-- task uses the abort statement to kill other tasks.
--
with Ada.Text_IO ;
with Interfaces ;
with GNAT.Sockets ;
use Ada.Text_IO ;
use Interfaces ;
use GNAT.Sockets ;
procedure v is
localhost : constant Inet_Addr_Type := Inet_Addr ( "127.0.0.1" ) ;
localport : constant Port_Type := 16#FFF0# ;
task One is
entry Start ; -- to insure network is operational
end One ;
task Two is
entry Start ;
end Two ;
task Three is
entry Start ;
end Three ;
task Main is
-- accept data from first two tasks.
entry Acknowledge_1 ( Data : Unsigned_32 ) ;
entry Acknowledge_2 ( Data : Unsigned_32 ) ;
-- accept data from third task only
entry Control ( Data : Character ) ;
-- denotes that network exception has ocurred from one of
-- the three tasks. The ( 1 .. 3 ) sets a range for
-- identifing the calling task. Where ( 1 ) is task One,
-- ( 2 ) is task Two and ( 3 ) is task Three.
entry Dead ( 1 .. 3 ) ;
end Main ;
--
-- Task bodies
--
task body One is
Socket : Socket_Type ;
Address : Sock_Addr_Type ;
Channel : Stream_Access ;
Data : Unsigned_32 ;
begin
-- Initialize Sockect
Create_Socket ( Socket, Family_Inet, Socket_Datagram ) ;
Address.Addr := localhost ;
Address.Port := localport + 1 ;
Connect_Socket ( Socket, Address ) ;
Channel := Stream ( Socket ) ;
accept Start ;
-- Wait for controller to activate
loop
-- Wait for data.
Unsigned_32'Read ( Channel, Data ) ;
-- Verify or Pre-process data, if needed
-- Send data to main task.
Main.Acknowledge_1 ( Data ) ;
end loop ;
exception
when Socket_Error =>
if Main'Callable then
Main.Dead ( 1 ) ;
end if ;
Close_Socket ( Socket ) ;
end One ;
task body Two is
Socket : Socket_Type ;
Address : Sock_Addr_Type ;
Channel : Stream_Access ;
Data : Unsigned_32 ;
begin
-- Initialize Sockect
Create_Socket ( Socket, Family_Inet, Socket_Datagram ) ;
Address.Addr := localhost ;
Address.Port := localport + 2 ;
Connect_Socket ( Socket, Address ) ;
Channel := Stream ( Socket ) ;
accept Start ;
-- Wait for controller to activate
loop
-- Wait for data.
Unsigned_32'Read ( Channel, Data ) ;
-- Verify or Pre-process data, if needed
-- Send data to main task.
Main.Acknowledge_2 ( Data ) ;
end loop ;
exception
when Socket_Error =>
if Main'Callable then
Main.Dead ( 2 ) ;
end if ;
Close_Socket ( Socket ) ;
end Two ;
task body Three is
Socket : Socket_Type ;
Address : Sock_Addr_Type ;
Channel : Stream_Access ;
Data : Character ;
begin
-- Initialize Sockect
Create_Socket ( Socket, Family_Inet, Socket_Datagram ) ;
Address.Addr := localhost ;
Address.Port := localport + 3 ;
Connect_Socket ( Socket, Address ) ;
Channel := Stream ( Socket ) ;
accept Start ;
-- Wait for controller to activate
loop
-- Wait for data.
Character'Read ( Channel, Data ) ;
-- Verify or Pre-process data, if needed
-- Send data to main task.
Main.Control ( Data ) ;
end loop ;
exception
when Socket_Error =>
if Main'Callable then
Main.Dead ( 3 ) ;
end if ;
Close_Socket ( Socket ) ;
end Three ;
--
-- Main Task body
--
task body Main is
Task_1_Data : Unsigned_32 ;
Task_2_Data : Unsigned_32 ;
Task_3_Data : Character ;
--
Task_Error : exception ;
begin
-- preform any initialize
loop
select
accept Acknowledge_1 ( Data : Unsigned_32 ) do
Task_1_Data := Data ;
-- process data from task 1
end Acknowledge_1 ;
or
accept Acknowledge_2 ( Data : Unsigned_32 ) do
Task_2_Data := Data ;
-- process data from task 2
end Acknowledge_2 ;
or
accept Control ( Data : Character ) do
Task_3_Data := Data ;
-- process data from task 3
end Control ;
or
accept Dead ( 1 ) ;
Put_Line ( "Error has ocurred in Task One" ) ;
raise Task_Error ;
or
accept Dead ( 2 ) ;
Put_Line ( "Error has ocurred in Task Two" ) ;
raise Task_Error ;
or
accept Dead ( 3 ) ;
Put_Line ( "Error has ocurred in Task Three" ) ;
raise Task_Error ;
end select ;
-- Continue processing with Data from all tasks
end loop ;
exception
when Task_Error =>
Put_Line ( "Error has cause this program to die" ) ;
-- abort all tasks
abort One ;
abort Two ;
abort Three ;
end Main ;
--
-- The Main task could start the three child task
--
begin
-- Verify all task are operational
if not One'Callable then
Put_Line ( "Error in Task One" ) ;
abort Two ;
abort Three ;
abort Main ;
elsif not Two'Callable then
Put_Line ( "Error in Task Two" ) ;
abort One ;
abort Three ;
abort Main ;
elsif not Three'Callable then
Put_Line ( "Error in Task Three" ) ;
abort One ;
abort Two ;
abort Main ;
else
One.Start ;
Two.Start ;
Three.Start ;
end if ;
exception
when others =>
null ;
end v ;
In <30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24>, "Ada @ BRL" <ada.brl.2011@gmail.com> writes:
>Hello,
>I'm an Erasmus student at the University of Bristol - UK and I'm carrying out the work for my master thesis in Computer Engineering.
>
>I'm programming a multithreading application in C / C++ and ADA.
>The latter is a completely new language for me...
>
>The environment of ADA applcation is:
>I have 4 tasks that execute at the same time:
>one is the main task,
>the other three execute a "read" from network (socket) function inside their bodies (on the other side there's the C/C++ application with 3 network sockets).
>[I decided to use the sockets instead of dll/lib import because this approach hasn't worked... =( ]
>
>I want that when new data is available on one or more socket threads, this / these threads somehow notify the main thread that data is arrived and then safely send the data to it.
>
>I've thought to use the interrupts...because I haven't found any references about the use of "events" in ADA.
>I've thought to attach three different handler of interrupts into the main task and then to generate the interrupt from the socket task with ada.interrupts.signal.generate_interrupt.
>Socket 1 will generate interrupt #1, socket 2 -> interrupt #2 and so on.
>
>May you tell me please if this is the right way to face the problem?
>I'm not skilled in ada and so there could be other better methods...
>
>I've used the pragmas attach_handler and interrupt_handler but unfortunately I'm still not able to get all the stuff working...
>
>I think it's a problem of ADA implementation because:
>even if I call pragma unreserve_all_interrupts I've found that the function Is_Reserved(Interr_ID) returns FALSE only for this signals IDs: 2(SIGINT), 4(SIGILL), 8(SIGFPE), 11(SISEGV), 15(SIGTERM), 22(SIGABRT).
>
>I guess that this is the opposite behaviour as I expected...
>If I try to set an handler to the interrupt say 9, the program cannot start due to this error:
>
>raised PROGRAM_ERROR : adjust/finalize raised PROGRAM_ERROR: s-interr.adb:343 explicit raise
>
>If I call the function Is_Attached the program suddenly exits:
>Program exited with code 01.
>(gdb)
>
>Do you know if is it possible to generate user defined interrupts?
>
>Can you help me please to find out what's the problem?
>Unfortunately there's not so much documentation about ADA =( and I'm late for my thesis...
>
>Thank you very much in advance for your help,
>Ada @ BRL
next prev parent reply other threads:[~2011-12-12 3:19 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-10 20:43 Interrupts handling in ADA Ada @ BRL
2011-12-10 21:13 ` Vinzent Hoefler
2011-12-10 22:09 ` Niklas Holsti
2011-12-10 22:27 ` Simon Wright
2011-12-11 20:21 ` Martin Dowie
2011-12-13 13:51 ` Ada BRL
2011-12-13 23:18 ` Martin Dowie
2011-12-13 14:11 ` Niklas Holsti
2011-12-13 14:54 ` Simon Wright
2011-12-13 15:06 ` Ada BRL
2011-12-13 21:49 ` Niklas Holsti
2011-12-13 23:18 ` Martin Dowie
2011-12-13 12:47 ` Ada BRL
2011-12-13 15:07 ` Simon Wright
2011-12-13 15:23 ` Ada BRL
2011-12-13 18:14 ` Simon Wright
2011-12-13 18:56 ` Ada BRL
2011-12-13 19:56 ` Bill Findlay
2011-12-13 22:15 ` Niklas Holsti
2011-12-13 15:34 ` Simon Wright
2011-12-13 17:55 ` Ada BRL
2011-12-13 18:18 ` Dmitry A. Kazakov
2011-12-13 19:01 ` Ada BRL
2011-12-13 19:58 ` Dmitry A. Kazakov
2011-12-13 18:24 ` Simon Wright
2011-12-11 0:15 ` Jeffrey Carter
2011-12-13 12:53 ` Ada BRL
2011-12-11 9:23 ` Dmitry A. Kazakov
2011-12-13 13:11 ` Ada BRL
2011-12-13 14:04 ` Dmitry A. Kazakov
2011-12-13 14:51 ` Ada BRL
2011-12-13 15:02 ` Ada BRL
2011-12-13 15:39 ` Dmitry A. Kazakov
2011-12-13 18:51 ` Ada BRL
2011-12-13 19:51 ` Dmitry A. Kazakov
2011-12-13 23:32 ` georg bauhaus
2011-12-11 12:04 ` Georg Bauhaus
2011-12-13 14:08 ` Ada BRL
2011-12-12 3:19 ` anon [this message]
2011-12-12 9:12 ` Niklas Holsti
2011-12-13 13:36 ` Ada BRL
2011-12-12 15:23 ` björn lundin
2011-12-13 13:38 ` Ada BRL
2011-12-13 13:56 ` Ludovic Brenta
2011-12-13 14:10 ` Ada BRL
2011-12-13 13:31 ` Ada BRL
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox