From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC,T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bdf72b2364b0da13 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.190.2 with SMTP id gm2mr7970585pbc.4.1323659968749; Sun, 11 Dec 2011 19:19:28 -0800 (PST) MIME-Version: 1.0 Path: lh20ni12511pbb.0!nntp.google.com!news1.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news2.dg.net.ua!news.ett.com.ua!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: Interrupts handling in ADA Date: Mon, 12 Dec 2011 03:19:26 +0000 (UTC) Organization: ETT newsserver Message-ID: References: <30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24> Reply-To: anon@anon.org NNTP-Posting-Host: dialup-4.225.170.40.dial1.dallas1.level3.net X-Complaints-To: usenet@news.ett.com.ua X-Notice: Filtered by postfilter v. 0.6.1 X-Newsreader: IBM NewsReader/2 2.0 Date: 2011-12-12T03:19:26+00:00 List-Id: -- 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" 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