Created
April 27, 2013 23:48
-
-
Save psyomn/5475221 to your computer and use it in GitHub Desktop.
Some Ada scraps from here and there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- @author Simon Symeonidis | |
| -- A messy way to stop tasks. Define a global variable and have the loop bodies | |
| -- for the tasks check that boolean variable if it is true or not, and continue | |
| -- the looping or not, respectively. | |
| with Ada.Text_IO; | |
| procedure konky is | |
| STOP_ANNOYING_PERSON : Boolean := False; | |
| task Annoying_Person is | |
| entry Start; | |
| entry Stop; | |
| end Annoying_Person; | |
| task Annoying_Persons_Friend is | |
| entry Start; | |
| entry Stop; | |
| end Annoying_Persons_Friend; | |
| task body Annoying_Person is | |
| begin | |
| accept Start; | |
| while not STOP_ANNOYING_PERSON loop | |
| Ada.Text_IO.Put_Line("Herp, derp derp, derp."); | |
| delay 0.8; | |
| end loop; | |
| end Annoying_Person; | |
| task body Annoying_Persons_Friend is | |
| begin | |
| accept Start; | |
| while not STOP_ANNOYING_PERSON loop | |
| Ada.Text_IO.Put_Line("Hurr durr?"); | |
| delay 1.32; | |
| end loop; | |
| end Annoying_Persons_Friend; | |
| begin | |
| Annoying_Person.Start; | |
| Annoying_Persons_Friend.Start; | |
| delay 2.0; | |
| Ada.Text_IO.Put_Line("Hey cut that out, or I'll terminate you!"); | |
| delay 2.0; | |
| Ada.Text_IO.Put_Line("Really, you guys are getting on my nerves!!"); | |
| delay 2.0; | |
| STOP_ANNOYING_PERSON := True; | |
| Ada.Text_IO.Put_Line("No more hurr durrs and herp derps!"); | |
| end konky; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- @author Simon Symeonidis | |
| -- @note thanks to: | |
| -- http://www.seas.gwu.edu/~mfeldman/cs2book/chap15.html | |
| -- | |
| -- Simple demonstration of using task types in order to create many different | |
| -- tasks and launch them. | |
| -- | |
| -- I know this is a crappy way to do this. | |
| with Ada.Text_IO; | |
| procedure Simple_Tasks is | |
| task type A is | |
| entry Start; | |
| end A; | |
| task type B is | |
| entry Start; | |
| end B; | |
| task body A is | |
| Max_Count : constant Integer := 100; | |
| Counter : Integer := 0; | |
| begin | |
| accept Start; | |
| loop | |
| exit when Counter >= Max_Count; | |
| Ada.Text_IO.Put("apples "); | |
| Counter := Counter + 1; | |
| end loop; | |
| end; | |
| task body B is | |
| Max_Count : constant Integer := 200; | |
| Counter : Integer := 0; | |
| begin | |
| accept Start; | |
| loop | |
| exit when Counter >= Max_Count; | |
| Ada.Text_IO.Put("oranges "); | |
| Counter := Counter + 1; | |
| end loop; | |
| end; | |
| a1, a2 : A; | |
| b1, b2 : B; | |
| begin | |
| a1.Start; | |
| b1.Start; | |
| a2.Start; | |
| b2.Start; | |
| end Simple_Tasks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment