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=-1.2 required=5.0 tests=BAYES_00,FROM_LOCAL_HEX, FROM_STARTS_WITH_NUMS 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.191.41 with SMTP id gv9mr5334623pbc.5.1323551602954; Sat, 10 Dec 2011 13:13:22 -0800 (PST) Path: lh20ni7804pbb.0!nntp.google.com!news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" <0439279208b62c95f1880bf0f8776eeb@t-domaingrabbing.de> Newsgroups: comp.lang.ada Subject: Re: Interrupts handling in ADA Date: Sat, 10 Dec 2011 22:13:28 +0100 Message-ID: References: <30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24> Mime-Version: 1.0 X-Trace: individual.net ew+qoM5aLk0t2MA2FXDSVABVjo93sNH6a+EulZABZ8UzuadKon Cancel-Lock: sha1:WGbmutA0185ty19vm2nWdlpBsAY= User-Agent: Opera Mail/11.60 (Win32) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Date: 2011-12-10T22:13:28+01:00 List-Id: Ada @ BRL wrote: > 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. You probably haven't seen references to protected types, then. (Although I am not sure, if a task rendezvous wouldn't even be more fit for your purpose...) > May you tell me please if this is the right way to face the problem? Well, not in Ada, no. ;) A quick and dirty approach (I'm missing the specs about what precisely you are trying to achieve, but then again, it's /your/ thesis.) But I sure hope, it gives you an idea at least... -- 8< -- type Source_Id is (Task_1, Task_2, Task_3); type Arrived_Flags is array (Source_Id) of Boolean; protected type Event is procedure Signal_Event (Source : in Source_Id); entry Wait (Source : out Source_Id); private Arrived : Arrived_Flags := (others => False); Event_Pending : Boolean := False; end Event; protected body Event is procedure Signal_Event (Source : in Source_Id) is begin -- Set flag for available source. Arrived_Flags (Source) := True; -- And set the barrier condition. Event_Pending := True; end Signal_Event; entry Wait (Source : out Source_Id) when Event_Pending is begin Find_Event: for S in Arrived'Range loop -- If event is marked as arrived, clear it and -- return the source id. if Arrived (S) then Source := S; Arrived (S) := False; exit Find_Event; end if; end loop; -- Paranoid thoughts: Shall we protect against uninitialized -- values of Source here or can we assume -- that at least one bit in the array was -- set if Event_Pending was actually True? -- No more events in Arrived? Lower the barrier again. Event_Pending := Arrived /= Arrived_Flags'(others => False); end Wait; end Event; (Haven't compiled it, so any errors are mine.) Now your main task could suspend on the wait entry of such a protected object whilst your communication task indicate their readiness via the Signal_Event protected procedure. How to exchange the data between the threads, well ... it could be done in the Wait entry, too, but that's something I'd like to be "left as an exercise for the reader". ;) Vinzent. -- f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.