comp.lang.ada
 help / color / mirror / Atom feed
From: sdm@cs.brown.edu (Scott Meyers)
Subject: Re: Activating tasks at global scope
Date: Thu, 11 Mar 1993 03:56:26 GMT
Date: 1993-03-11T03:56:26+00:00	[thread overview]
Message-ID: <1993Mar11.035626.7824@cs.brown.edu> (raw)
In-Reply-To: EACHUS.93Mar10121115@goldfinger.mitre.org

In article <EACHUS.93Mar10121115@goldfinger.mitre.org> 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."



  reply	other threads:[~1993-03-11  3:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-03-10  3:32 Activating tasks at global scope Scott Meyers
1993-03-10 17:11 ` Robert I. Eachus
1993-03-11  3:56   ` Scott Meyers [this message]
1993-03-11 17:57     ` Dave Collard x7468
1993-03-11  2:51 ` Michael Feldman
1993-03-11  2:54   ` second half of portable diners Michael Feldman
  -- strict thread matches above, loose matches on Subject: below --
1993-03-15 14:58 Activating tasks at Global Scope Cheryl Marquis
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox