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.9 required=5.0 tests=BAYES_00 autolearn=ham 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.213.71 with SMTP id nq7mr5432877pbc.2.1323556061236; Sat, 10 Dec 2011 14:27:41 -0800 (PST) Path: lh20ni8003pbb.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Interrupts handling in ADA Date: Sat, 10 Dec 2011 22:27:39 +0000 Organization: A noiseless patient Spider Message-ID: References: <30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="30841"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WOKBI9tFT1UqoLCZGpREi+TLKBWgs6Yg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:zaTP3dKbLBEgQW3heUD5IeNB28I= sha1:4vzoPV26BQLibgEo9T+yCYZ/A1o= Content-Type: text/plain; charset=us-ascii Date: 2011-12-10T22:27:39+00:00 List-Id: "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 with Ada.Containers.Vectors; package Queueing is type Message is new Integer; package Queue_Data is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Message); protected Queue is procedure Put (M : Message); entry Get (M : out Message); private Buffer : Queue_Data.Vector; end Queue; end Queueing; and (as a hint) the body of the Get entry might start like entry Get (M : out Message) when not Buffer.Is_Empty is 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-18-2.html [2]http://en.wikibooks.org/wiki/Ada_Programming/Tasking#Protected_types