* Terminating a task @ 2003-07-12 14:03 kat-Zygfryd 2003-07-12 14:37 ` kat-Zygfryd 0 siblings, 1 reply; 10+ messages in thread From: kat-Zygfryd @ 2003-07-12 14:03 UTC (permalink / raw) If I have a task running Get_Line (from an AdaSocket) how can I terminate this task from within another task? Simply shutting down the socket doesn't work as the thread is interrupted by an exception only when there is data sent from the client attached to the socket. kZ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-12 14:03 Terminating a task kat-Zygfryd @ 2003-07-12 14:37 ` kat-Zygfryd 2003-07-14 9:34 ` Craig Carey 0 siblings, 1 reply; 10+ messages in thread From: kat-Zygfryd @ 2003-07-12 14:37 UTC (permalink / raw) I tried to use Abort_Task but the whole program terminates with a message that the environment task has terminated. But it is not the main program task that I'm trying to abort... kZ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-12 14:37 ` kat-Zygfryd @ 2003-07-14 9:34 ` Craig Carey 2003-07-14 23:45 ` Matthew Heaney 0 siblings, 1 reply; 10+ messages in thread From: Craig Carey @ 2003-07-14 9:34 UTC (permalink / raw) On Sat, 12 Jul 2003 16:03:27 +0200, "kat-Zygfryd" <6667@wp.pl> wrote: >If I have a task running Get_Line (from an AdaSocket) >how can I terminate this task from within another task? >Simply shutting down the socket doesn't work as >the thread is interrupted by an exception only when >there is data sent from the client attached to the socket. On Sat, 12 Jul 2003 16:37:09 +0200, "kat-Zygfryd" <6667@wp.pl> wrote: >I tried to use Abort_Task but the whole program >terminates with a message that the environment task If a task is blocked on a socket then either close that socket or shutdown the TCP stack. This text would not be correct if the source code was rewritten: "Simply shutting down the socket doesn't work as ... " PS. With GNAT 3.15 in Linux/etc., to get Ctrl-C running safely, user- side code is written to unblock all blocking statements in tasks. ------------ PS. The new "Computer Language Shootout" website now has Ada. http://dada.perl.it/shootout/index.html GNAT Ada came first of 32 entries in one OO speed test http://dada.perl.it/shootout/methcall.html My "wc" word count program got eliminated probably since the tester could not link in Win32 "_setmode" and "_read". (Ada 95 packages do not allow accurate reading from the standard input). At least 3 of the Ada examples vanished (including a regular expressions example), probably for having too many lines in a package (strings, hashes). Some C programmers decided to have their 'sumcol' entries pick the first number when a line contained 2 numbers and it seemed incorrect: http://dada.perl.it/shootout/sumcol.html Craig Carey -------------------------- How To Cross-Compile to a Linux target while compiling in a FreeBSD 5 host. Some new instructions are here: http://www.ijs.co.nz/code/ada95-freebsd-to-linux-cross-compiler.txt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-14 9:34 ` Craig Carey @ 2003-07-14 23:45 ` Matthew Heaney 2003-07-15 17:49 ` Craig Carey 2003-07-15 22:37 ` Robert I. Eachus 0 siblings, 2 replies; 10+ messages in thread From: Matthew Heaney @ 2003-07-14 23:45 UTC (permalink / raw) Craig Carey <research@ijs.co.nz> wrote in message news:<ubs4hv4eaar8hbmr2vut59ananvsuvra9a@4ax.com>... > > PS. The new "Computer Language Shootout" website now has Ada. > > http://dada.perl.it/shootout/index.html > > My "wc" word count program got eliminated probably since the tester > could not link in Win32 "_setmode" and "_read". (Ada 95 packages do not > allow accurate reading from the standard input). Your word count program got eliminated because it is junk. I have no idea what you mean about not being able to accurately read from standard input. Here is a simplified version of the program, which closely follows the gcc example: with Ada.Text_IO; use Ada.Text_IO; with Ada.Characters.Latin_1; use Ada.Characters; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure WC is Line : String (1 .. 133); Last : Natural; NL, NW, NC : Integer'Base := 0; Word : Boolean := False; begin while not End_Of_File loop Get_Line (Line, Last); NC := NC + Last; for I in Line'First .. Last loop if Line (I) = Latin_1.Space or Line (I) = Latin_1.HT then Word := False; elsif not Word then Word := True; NW := NW + 1; end if; end loop; if Last < Line'Last then Word := False; NL := NL + 1; end if; end loop; Put ("NL="); Put (NL, Width => 0); New_Line; Put ("NW="); Put (NW, Width => 0); New_Line; Put ("NC="); Put (NC, Width => 0); New_Line; end WC; -Matt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-14 23:45 ` Matthew Heaney @ 2003-07-15 17:49 ` Craig Carey 2003-07-15 18:30 ` David C. Hoos 2003-07-16 5:26 ` Matthew Heaney 2003-07-15 22:37 ` Robert I. Eachus 1 sibling, 2 replies; 10+ messages in thread From: Craig Carey @ 2003-07-15 17:49 UTC (permalink / raw) On 14 Jul 2003 16:45:32 -0700, mheaney@on2.com (Matthew Heaney) wrote: >> PS. The new "Computer Language Shootout" website now has Ada. >> >> http://dada.perl.it/shootout/index.html >> >> My "wc" word count program got eliminated probably since the tester >> could not link in Win32 "_setmode" and "_read". (Ada 95 packages do not >> allow accurate reading from the standard input). I correct that: Mr A. Calpini can link (gnatmake runs easily). >Your word count program got eliminated because it is junk. I have not got a statement of the reasoning and I have requested that. I guess that the contest person would reply. ... >I have no idea what you mean about not being able to accurately read >from standard input. Ada 95 can't read data accurately from the console: (a) Text_IO has an undefined behaviour on what bounds lines. The Stream_IO package does not let the standard input be specified. GNAT extensions were not used (i.e. fread() in Interfaces.C_Streams). AARM A.12.1 The Package Streams.Stream_IO" http://www.adaic.org/standards/95aarm/html/AA-A-12-1.html >Here is a simplified version of the program, which closely follows the >gcc example: > My code is better: http://dada.perl.it/shootout/gnat_allsrc.html >with Ada.Text_IO; use Ada.Text_IO; [...] >procedure WC is ... > while not End_Of_File loop > Get_Line (Line, Last); A program called "word counter" need not receive data containing text. The 'wc' specs agree: http://www.bagley.org/~doug/shootout/bench/wordfreq/ Ada.Text_IO was not portable over to ObjectAda 7.2.2: End_Error on a missing NL at the end of the file. Using Ada.Text_IO's Read_Line is not safe in presumably all samples programs if GNAT might not be used. Correctness testing could appear later. Poplog LISP was losing entries: http://dada.perl.it/shootout/poplisp.html The New Shootout: http://dada.perl.it/shootout/ Old site has e-mail addr. Craig Carey GNAT's C++ Cpp_Virtual pragma: http://www.ijs.co.nz/code/ada_95_gnat_bindings_to_cpp_example_program.txt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-15 17:49 ` Craig Carey @ 2003-07-15 18:30 ` David C. Hoos 2003-07-16 5:26 ` Matthew Heaney 1 sibling, 0 replies; 10+ messages in thread From: David C. Hoos @ 2003-07-15 18:30 UTC (permalink / raw) To: comp.lang.ada; +Cc: Craig Carey "Craig Carey" <research@ijs.co.nz> wrote in message news:5ra8hvkkabsvevc2r0abu4mp71dfochelr@4ax.com... > <snip> > Ada 95 can't read data accurately from the console: (a) Text_IO has an > undefined behaviour on what bounds lines. The Stream_IO package does not > let the standard input be specified. GNAT extensions were not used (i.e. > fread() in Interfaces.C_Streams). What do you mean by "Text_IO has an undefined behaviour on what bounds lines."? The procedures Ada.Text_IO.Get_Line and Ada.Text_IO.Put_Line certainly know what "bounds lines." True, the Stream_IO package does not allow the standard input to be specified, but that's not the proper package to use for dealing with _text_ streams. The package Ada.TextIO.Text_Streams allows one to obtain the stream object corresponding to the standard input -- i.e.: Standard_Input_Stream : Ada.Text_IO.Text_Streams.Stream_Access = Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Standard_Input); ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-15 17:49 ` Craig Carey 2003-07-15 18:30 ` David C. Hoos @ 2003-07-16 5:26 ` Matthew Heaney 1 sibling, 0 replies; 10+ messages in thread From: Matthew Heaney @ 2003-07-16 5:26 UTC (permalink / raw) "Craig Carey" <research@ijs.co.nz> wrote in message news:5ra8hvkkabsvevc2r0abu4mp71dfochelr@4ax.com... > > Ada 95 can't read data accurately from the console: (a) Text_IO has an > undefined behaviour on what bounds lines. No, Text_IO doesn't define what control characters terminate a line, but that's the whole point, to abstract away the representation of a line of text. And of course, the behavior of Text_IO wrt consumption of a line of text is defined. So I still don't know what you're talking about. The programs I posted all work fine using Text_IO. >The Stream_IO package does not > let the standard input be specified. GNAT extensions were not used (i.e. > fread() in Interfaces.C_Streams). This is irrelevent. The point of the shootout was to use the standard idioms for the language. So in Ada, if you want to consume a line of text from standard input, that means using Text_IO.Get_Line. To test whether you've consumed the entire line, do this: declare Line : String (1 .. N); Last : Natural; begin Get_Line (Line, Last); if Last < Line'Last then --we've consumed the entire line ... end; See my CLA post with the subject "Get_Line Mystery" (it's archived at adapower.com), which explains how Get_Line works. > My code is better: http://dada.perl.it/shootout/gnat_allsrc.html Your code is a completely incomprehensible mess. > A program called "word counter" need not receive data containing text. I don't care to speculate what the behavior is of a program that counts lines of text, if the input isn't text. Certainly, the input.txt file he used to test the wc programs is text, so it is pointless to debate what should happen if the input file is not text. > Ada.Text_IO was not portable over to ObjectAda 7.2.2: End_Error on a > missing NL at the end of the file. The program I wrote should not raise End_Error. If it does, then the compiler is broken, and you should take the matter up with Aonix. > Using Ada.Text_IO's Read_Line is not > safe in presumably all samples programs if GNAT might not be used. I am not familiar with any Text_IO operation called Read_Line. -Matt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-14 23:45 ` Matthew Heaney 2003-07-15 17:49 ` Craig Carey @ 2003-07-15 22:37 ` Robert I. Eachus 2003-07-16 5:00 ` Matthew Heaney 1 sibling, 1 reply; 10+ messages in thread From: Robert I. Eachus @ 2003-07-15 22:37 UTC (permalink / raw) Matthew Heaney wrote: > Here is a simplified version of the program, which closely follows the > gcc example: > > > with Ada.Text_IO; use Ada.Text_IO; > with Ada.Characters.Latin_1; use Ada.Characters; > with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; > > procedure WC is > > Line : String (1 .. 133); > Last : Natural; > > NL, NW, NC : Integer'Base := 0; > > Word : Boolean := False; > > begin > > while not End_Of_File loop > > Get_Line (Line, Last); > > NC := NC + Last; > > for I in Line'First .. Last loop > if Line (I) = Latin_1.Space or Line (I) = Latin_1.HT then > Word := False; > > elsif not Word then > Word := True; > NW := NW + 1; > > end if; > end loop; > > if Last < Line'Last then > Word := False; > NL := NL + 1; > end if; > > end loop; > > Put ("NL="); Put (NL, Width => 0); New_Line; > Put ("NW="); Put (NW, Width => 0); New_Line; > Put ("NC="); Put (NC, Width => 0); New_Line; > > end WC; If you change: if Last < Line'Last then... to: if End_of_Line then Word := False; NL := NL + 1; end if; maybe that will end the 'discussion' about whether it is possible to count lines properly in Ada. Oh, you might want to stick: exit when End_of_File; after the call to Get_Line. Of course the need to do that or not depends on the number of lines and characters you want to count for the implict End_of_Page at the end of the file. Notice that with these changes your program should work fine even if you set Line to String(1..10); -- Robert I. Eachus �In an ally, considerations of house, clan, planet, race are insignificant beside two prime questions, which are: 1. Can he shoot? 2. Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and Steve Miller. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-15 22:37 ` Robert I. Eachus @ 2003-07-16 5:00 ` Matthew Heaney 2003-07-16 18:19 ` Robert I. Eachus 0 siblings, 1 reply; 10+ messages in thread From: Matthew Heaney @ 2003-07-16 5:00 UTC (permalink / raw) "Robert I. Eachus" <rieachus@attbi.com> wrote in message news:3F148227.6060702@attbi.com... > > If you change: > if Last < Line'Last then... > > to: > if End_of_Line then > Word := False; > NL := NL + 1; > end if; > > maybe that will end the 'discussion' about whether it is possible to > count lines properly in Ada. Why should this make a difference? The idiom in my example is per Ada83 AI-50. What does End_Of_Line do, that Last < Line'Last does not? >Oh, you might want to stick: > > exit when End_of_File; > > after the call to Get_Line. Of course the need to do that or not > depends on the number of lines and characters you want to count for the > implict End_of_Page at the end of the file. The canonical wc program in the shootout seems to count the line terminator among the count of characters. The program I posted does not. To make the outputs match all you'd need to do is add the line count to the character count, to make up the difference. Other than that, given the input.txt file at the shootout page, the wc program I posted gives the correct results. So I'm not sure why anyone thinks there is a problem. Except for the interpretation of character count, as far as I can tell the program I wrote is correct as is. > Notice that with these > changes your program should work fine even if you set Line to > String(1..10); But that's true even without your changes. In fact before I posted the program, I tested it using String (1 .. 5) as the subtype indication, and it worked fine. -Matt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Terminating a task 2003-07-16 5:00 ` Matthew Heaney @ 2003-07-16 18:19 ` Robert I. Eachus 0 siblings, 0 replies; 10+ messages in thread From: Robert I. Eachus @ 2003-07-16 18:19 UTC (permalink / raw) Matthew Heaney wrote: > But that's true even without your changes. In fact before I posted the > program, I tested it using String (1 .. 5) as the subtype indication, and it > worked fine. Yep, sorry. I checked your code in the light of day, and for this case it is fine. The only potential issue is counting one "extra" line if have an Ada file with an explicit end of page marker at the end of the file. (With most Ada compilers you have to work to manage that. Of course, the ACATS tests do just that...) -- Robert I. Eachus �In an ally, considerations of house, clan, planet, race are insignificant beside two prime questions, which are: 1. Can he shoot? 2. Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and Steve Miller. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2003-07-16 18:19 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-07-12 14:03 Terminating a task kat-Zygfryd 2003-07-12 14:37 ` kat-Zygfryd 2003-07-14 9:34 ` Craig Carey 2003-07-14 23:45 ` Matthew Heaney 2003-07-15 17:49 ` Craig Carey 2003-07-15 18:30 ` David C. Hoos 2003-07-16 5:26 ` Matthew Heaney 2003-07-15 22:37 ` Robert I. Eachus 2003-07-16 5:00 ` Matthew Heaney 2003-07-16 18:19 ` Robert I. Eachus
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox