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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,126ce244c524526b X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Tasking issues Reply-To: anon@anon.org (anon) References: <1186851804.567302.223160@q4g2000prc.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Sun, 12 Aug 2007 09:00:27 GMT NNTP-Posting-Host: 12.65.42.102 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1186909227 12.65.42.102 (Sun, 12 Aug 2007 09:00:27 GMT) NNTP-Posting-Date: Sun, 12 Aug 2007 09:00:27 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:1406 Date: 2007-08-12T09:00:27+00:00 List-Id: -- -- This works and is almost the same code that you used. -- Exceptions to make the program function with the ability -- to stop task. -- -- For help it is better that you write your code -- test with -- gnatmake main.adb -- then for help compile with: -- gnat1 main.adb -gnatl >main.lst -- -- Then copy and paste the main.lst file to your post -- so that we can the compiler errors. Without too -- much editing of the code. -- with Ada.Text_io ; use Ada.Text_io ; procedure main is task get_name; task print_something; continue : boolean := True ; -- task to continue running task body get_name is Name : String ( 1 .. 25 ) ; Last : Integer ; begin loop Get_Line ( Name, Last ) ; -- Set stop flag if Name ( 1 .. 4 ) = "stop" then continue := false ; end if ; delay 0.0 ; end loop ; end get_name ; task body print_something is begin loop Put_Line ( "blah..." ) ; delay 0.0 ; end loop ; end print_something ; begin --- main -- do nothing! while continue loop delay 0.0 ; end loop ; -- abort tasks. But because get_name may be in the process of -- obtaining data from standard_input. it may require a CR/LF -- to be entered to fully abort the 'get_name' task. abort get_name ; Put_Line ( "EOT -- get_name" ) ; abort print_something ; Put_Line ( "EOT -- print_something" ) ; Put_Line ( "EOJ" ) ; end main; In <1186851804.567302.223160@q4g2000prc.googlegroups.com>, shaunpatterson@gmail.com writes: >I'm having trouble with tasking in Ada. I'm used to working with >pthreads >in C/C++... and I'm finding tasks to be somewhat different/annoying. > >My basic problem is I want to have 2 threads in my program. > >One thread sits in the background and reads in messages, >dispatches them, etc and the other thread reads off a queue >and sends out messages when they are available. > >As an analogy, let's assume my background task just got >input from the user (simulating the socket read) and the other >task just printed out stuff. > >Something like > >procedure main is >begin > task get_name; > task print_something; > > task body get_name is > Name : String (1..25); > Last : Integer; > begin > loop > Get_Line (Name, Last); > end loop; > end get_name; > > task body print_something is > begin > loop > Put_Line ("blah..."); > end loop; > end print_something; > >begin --- main > > loop; > null; > end loop; >end main; > > >Of course, this doesn't work as I'd expect. Is there a way to >"timeout" the >first get_name thread... so the OS only waits on that thread for a >short period >of time to allow the other threads to do their business? and then go >back to >the thread? > >Thanks >-- Shaun >