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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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 Received: by 10.68.190.2 with SMTP id gm2mr12582461pbc.4.1323780475302; Tue, 13 Dec 2011 04:47:55 -0800 (PST) Path: lh20ni17731pbb.0!nntp.google.com!news2.google.com!postnews.google.com!r6g2000yqr.googlegroups.com!not-for-mail From: Ada BRL Newsgroups: comp.lang.ada Subject: Re: Interrupts handling in ADA Date: Tue, 13 Dec 2011 04:47:54 -0800 (PST) Organization: http://groups.google.com Message-ID: <6df577eb-9c6a-4f82-95e4-817f6ad1ba6e@r6g2000yqr.googlegroups.com> References: <30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24> NNTP-Posting-Host: 164.11.203.58 Mime-Version: 1.0 X-Trace: posting.google.com 1323780475 21934 127.0.0.1 (13 Dec 2011 12:47:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Dec 2011 12:47:55 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r6g2000yqr.googlegroups.com; posting-host=164.11.203.58; posting-account=yig7mwoAAAAAcduNbH7Dpal1sjCSAijA User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUARELSCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-12-13T04:47:54-08:00 List-Id: On 10 Dic, 22:27, Simon Wright wrote: > "Ada @ BRL" writes: > > > The environment of ADA applcation is: > > Ada, please! > > > > > 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 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. > > First off, I'd use a Queue. > > The new Ada2012 standard includes a synchronised Queue, which would be > just what you want out of the box, but you won't find that in the > current compilers, so you'll need to roll your own. > > Starting from Ada.Containers.Vectors[1], the Queue abstraction would > come from using Append to put new mesages on the queue, Is_Empty to > check whether there's something to get from the queue, and First_Element > followed by Delete_First to fetch the front element. > > You then need to wrap this container in a protected object[2], so that > the updates from the different input tasks don't corrupt each other, and > so that the main task can block until there's something to read. Use a > Put procedure to post messages onto the queue, and a Get entry to read > the next message or block if there isn't one. > > The spec might look like > > =A0 =A0with Ada.Containers.Vectors; > =A0 =A0package Queueing is > =A0 =A0 =A0 type Message is new Integer; > =A0 =A0 =A0 package Queue_Data > =A0 =A0 =A0 is new Ada.Containers.Vectors (Index_Type =3D> Natural, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0Element_Type =3D> Message); > =A0 =A0 =A0 protected Queue is > =A0 =A0 =A0 =A0 =A0procedure Put (M : Message); > =A0 =A0 =A0 =A0 =A0entry Get (M : out Message); > =A0 =A0 =A0 private > =A0 =A0 =A0 =A0 =A0Buffer : Queue_Data.Vector; > =A0 =A0 =A0 end Queue; > =A0 =A0end Queueing; > > and (as a hint) the body of the Get entry might start like > > =A0 =A0 =A0 entry Get (M : out Message) when not Buffer.Is_Empty is > =A0 =A0 =A0 begin > > If your input messages are not all the same type (in Ada-speak, type > Message is indefinite), things get more complicated; but let's cross > that bridge only if we need to. > > [1]http://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-1.= .. > [2]http://en.wikibooks.org/wiki/Ada_Programming/Tasking#Protected_types Thank you for the reply! Please tell me if I'm wrong: - inside the main task I must use an accept statement "Get": by doing it, this means that the main task wait on this "barrier" until there is something inside the protected object queue; when entry Get is available (due to the incoming data), the main task is automatically notified and it executes the Get function, isnt' it? So the entry / accept paradigm is something like events in C? So the main task doesn't has to constantly poll the queue; the entry / accept statement do it by itself. Am I right? Thank everyone for the help!!!