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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d11f89f2e445c0a7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-03-10 20:11:22 PST Newsgroups: comp.lang.ada Path: sparky!uunet!brunix!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Subject: Re: Activating tasks at global scope Message-ID: <1993Mar11.035626.7824@cs.brown.edu> Sender: news@cs.brown.edu Organization: Brown University Department of Computer Science References: <1993Mar10.033256.24718@cs.brown.edu> Date: Thu, 11 Mar 1993 03:56:26 GMT Date: 1993-03-11T03:56:26+00:00 List-Id: In article eachus@goldfinger.mitre.org (Robert I. Eachus) writes: | You were doing fine, but got bitten by a very subtle feature of Ada. | The tasks were all created and elaborated before the main program | executed, but then the main program immediately exited. The language | reference manual leaves it unspecifed what happens to library tasks in | such a situation, but most implementations now terminate them all if | they are quiescent. So your tasks disappeared from view before they | could act. | | In any case try hanging your main program, either by putting in a | delay statement or by waiting for input...the elegent final version | should have a clean way of terminating the program, but this will do | for testing. I tried to follow this advice, but none of the tasks appears to run; certainly the output statements in their initialization blocks are never executed. I've appended the full program below, and I'd appreciate it if somebody could help me figure out what's wrong. Trust me when I tell you I've tried to solve this problem myself. (I had quite a lovely time determining that the behavior of the Ada/Ed compiler is dependent in part on the name of the file containing the source, and I don't mean the file extensions. In particular, the compiler generates an internal error on a whole host of file names. Names containing numbers seem to be particularly offensive to it...) Thanks for your help, Scott with Text_IO; use Text_IO; package Buffer_Package is task Buffer is entry insert(item: in Integer); entry remove(item: out Integer); end Buffer; end Buffer_Package; package body Buffer_Package is task body Buffer is count: Integer := 0; begin loop select when count < 10 => accept insert(item: in Integer) do -- insert item into the buffer PUT_LINE("ACCEPTING AN INSERTION"); null; end insert; count := count + 1; or when count > 0 => accept remove(item: out Integer) do -- remove an object from the buffer and assign it to item PUT_LINE("ACCEPTING A REMOVAL"); null; end remove; count := count - 1; end select; end loop; end Buffer; begin PUT_LINE("STARTING BUFFER_PACKAGE"); end Buffer_Package; -------------------------------------------------------------------------- with Text_IO; use Text_IO; with Buffer_Package; use Buffer_Package; package Producer_Package is task Producer; end Producer_Package; package body Producer_Package is task body Producer is n: integer; begin loop -- give n an appropriate value PUT_LINE("INSERTING"); Buffer.insert(n); end loop; end Producer; begin PUT_LINE("STARTING PRODUCER_PACKAGE"); end Producer_Package; -------------------------------------------------------------------------- with Text_IO; use Text_IO; with Buffer_Package; use Buffer_Package; package Consumer1_Package is task Consumer1; end Consumer1_Package; package body Consumer1_Package is task body Consumer1 is n: integer; begin loop PUT_LINE("REMOVING2"); Buffer.remove(n); -- do something with n end loop; end Consumer1; begin PUT_LINE("STARTING CONSUMER1_PACKAGE"); end Consumer1_Package; -------------------------------------------------------------------------- with Text_IO; use Text_IO; with Buffer_Package; use Buffer_Package; package Consumer2_Package is task Consumer2; end Consumer2_Package; package body Consumer2_Package is task body Consumer2 is n: integer; begin loop PUT_LINE("REMOVING2"); Buffer.remove(n); -- do something with n end loop; end Consumer2; begin PUT_LINE("STARTING CONSUMER2_PACKAGE"); end Consumer2_Package; -------------------------------------------------------------------------- with Text_IO; use Text_IO; procedure producer_consumer is begin PUT_LINE("STARING DELAY..."); delay 5.0; PUT_LINE("DONE."); end producer_consumer; ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."