Shared Variables

Stack Example 2


PACKAGE BODY stack_of_integer IS
    TYPE stack_type IS ARRAY (0 to 100) OF INTEGER;
    SHARED VARIABLE stack : stack_type;
    SHARED VARIABLE index : NATURAL := 0;
 
    PROCEDURE push (what : IN INTEGER) IS
    BEGIN
      stack(index) := what;
      index := index + 1;
    END push;

    PROCEDURE pop (what : OUT INTEGER) IS
    BEGIN
      index := index - 1;
      what := stack(index);
    END pop;
END PACKAGE BODY stack_of_integer;

[Berge93]

Copyright © 1993 by Kluwer Academic Publishers. Reprinted by permission.