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,136c120daac2a1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!news3.google.com!news.glorb.com!guardian.oit.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!nntp.abs.net!news.abs.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: tasksing and TCP sockets References: <1138659171.491931.322480@g49g2000cwa.googlegroups.com> From: Stephen Leake Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:9PVobneD2wbnA6nJ8b4/MY1SOmA= MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Mon, 30 Jan 2006 21:40:23 -0500 NNTP-Posting-Host: 66.159.65.1 X-Complaints-To: abuse@toad.net X-Trace: news.abs.net 1138675230 66.159.65.1 (Mon, 30 Jan 2006 21:40:30 EST) NNTP-Posting-Date: Mon, 30 Jan 2006 21:40:30 EST Xref: g2news1.google.com comp.lang.ada:2719 Date: 2006-01-30T21:40:23-05:00 List-Id: "Rolf" writes: > Consider an application that communicates with its environment via > sensors and actors. For testing purposes the low level access to the > sensor and actor data gets replaced by a TCP socket communication whose > other end simulates the world, i.e. the world simulation continuously > writes sensor data to the socket and accepts commands as actor data. > > +-----------------------+ > | | > | application | > | | > +-----------------------+ > | h/w abstraction | > | sensors | actors | > +-----------------------+ > | > TCP client > | > | > | > TCP server that simulates the world > Ok, this makes sense. > In a stripped down version I can succesfully connect to the server > (using GNAT.Sockets) and either read the sensor data *or* write actor > data. The program is currently split in two tasks. One tasks contains > the application code and the actor communication (using > type_id'output(channel)). The second tasks gets started during program > initialisation. It reads the data from the socket via > type_id'input(channel) and provides the data to the application through > a protected object. > > The problem that I face is that the second task seems to starve the > first one. As soon as it is active, the application does not generate > debug output anymore. You need to set the priorities correctly, and you need to ensure that there are no busy waits; the second task should be _suspended_ waiting on socket completions, not polling for them. And the simulator must send data at a reasonable rate, not too fast. > Some background info: gcc-3.4.4 on Windows XP. That may be a problem. I find the commercially supported GNAT to be less broken. > Java for the world simulation. Yuck. I assume that's not by choice? > The simulator sends about 20 packages � 11bytes every 100ms. The > application sends typically 2-3 packages per second. That's certainly "reasonable rates" > I have delay statements in both main loops (varied between 0.0 and > 0.2 seconds). You should _not_ need delay statements. Redesign to be waiting on socket completions. Or, if you are designing to a cyclic execution, you can poll on the sockets, but just once per cycle. You can use GNAT.Sockets.Control_Socket for that. > My questions: > - is that a reasonable tasking approach? In general, yes. But the details matter a lot. > - I don't know much about sockets (or better I don't remember > much). Does a waiting read (in the second task) block a write in the > first task? Not in Windows with GNAT 5.03a. gcc-3.4.4 on Cygwin may be different. > - how can I interrupt the waiting read task to force activity in the > main task? Depends on how it is waiting. If is in a GNAT.Sockets.Receive_Socket, you can't (short of shutting down the socket). So periodic polling might be better. > - what other hints can you give me? Get an AdaCore support contract. -- -- Stephe